Reputation: 43
Here is the code so far:
bool t1 = true;
bool f1 = false;
bool button_state = 0;
int delay_led = 100;
int led_num = 1, buzzer_delay = 75;
void setup() {
// put your setup code here, to run once:
pinMode(2, INPUT); pinMode(10, OUTPUT); pinMode(11, OUTPUT);
pinMode(12, OUTPUT); pinMode(13, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalRead(2);
button_state = digitalRead(2);
if (button_state == 0)
{
for (led_num = 10; led_num <= 13; led_num++)
{
digitalWrite(led_num, t1);
delay(delay_led);
digitalWrite(led_num, f1);
}
}
else
{
for (led_num >= 10; led_num <= 13; led_num++)
{
digitalWrite(led_num, t1);
}
}
}
I'm trying to get the LEDs to light up at once, which is what the else statement is used for. However, our instructor specifically stated to use loops to accomplish this. Here is our assignment:
Here is an image of our assignment
I cannot figure out how to use loops instead on the if/else and I cannot get the LEDs to light up at once. Any help would be greatly appreciated!
Upvotes: 0
Views: 57
Reputation: 15501
Your second foor
loop init-statement of led_num >= 10
is wrong as it has no effect. Instead of:
for (led_num >= 10; led_num <= 13; led_num++)
it should probably be:
for (led_num = 11; led_num <= 13; led_num++)
Upvotes: 1