Hi Forum-members,
First a small introduction, because i am new here,
recently accuiered a teensyboard to learn coding, and what al the possibilities are with it.
i was looking for the newbie-questions-section to give room to the more experienced users, but coulnd find it.
(i guess this is a propper newbie guestion )
so i try to wrap my head around the if,else,and,or and try to code some basics. with three buttons and three led, and also the onboard led.
But it looks like, that what i try to do, works the opposite way than the logic in my head, and what the reactions are if i program the board. (its good fun, but not the way i wanted it to respond)
so what i try to do, is 3 buttons and three leds all activated on its own like
Button1 = led1, etc etc etc,
but when pushing all the buttons at the same time, nothing should happen : all leds off, only the onboard led (13) can light up.
ive included the sketch, (i know i am not at the finished code) would be appreciated if one could have a quick look, and guide me in the right direction.
(or a good link with some more detailed info, i am getting stuck here on this site, and more google madness)
Thanks in advance
yours
Danny
First a small introduction, because i am new here,
recently accuiered a teensyboard to learn coding, and what al the possibilities are with it.
i was looking for the newbie-questions-section to give room to the more experienced users, but coulnd find it.
(i guess this is a propper newbie guestion )
so i try to wrap my head around the if,else,and,or and try to code some basics. with three buttons and three led, and also the onboard led.
But it looks like, that what i try to do, works the opposite way than the logic in my head, and what the reactions are if i program the board. (its good fun, but not the way i wanted it to respond)
so what i try to do, is 3 buttons and three leds all activated on its own like
Button1 = led1, etc etc etc,
but when pushing all the buttons at the same time, nothing should happen : all leds off, only the onboard led (13) can light up.
ive included the sketch, (i know i am not at the finished code) would be appreciated if one could have a quick look, and guide me in the right direction.
(or a good link with some more detailed info, i am getting stuck here on this site, and more google madness)
Thanks in advance
yours
Danny
Code:
void setup() {
pinMode(8, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP);
pinMode(10, INPUT_PULLUP);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
pinMode(14, OUTPUT);
}
void loop()
{
if (digitalRead(8) == HIGH) {
digitalWrite(11, LOW);
}
else {
digitalWrite(11, HIGH);
}
if (digitalRead(9) == HIGH) {
digitalWrite(12, LOW);
}
else {
digitalWrite(12, HIGH);
}
if (digitalRead(10) == HIGH) {
digitalWrite(14, LOW);
}
else {
digitalWrite(14, HIGH);
}
if (digitalRead(8) == HIGH && digitalRead(9) == HIGH && digitalRead(10)== HIGH) {
digitalWrite(13, HIGH);
}
else {
digitalWrite(13, LOW);
}
delay(10);
}
Last edited by a moderator: