Trying to understand conditions.
i'm trying pick c++ through arduino, , i've gotten point i'm trying use conditions in different applications learn how work.
unfortunately i've come across situation notice knowledge limited, , can't see why, after several google searches, i'm hoping in here might able point me in correct direction.
the application basic one: have 2 led's want flash sequentially, first one, other. should go on indefinitely.
i've gotten work while loop, if loop doesn't work, , keep 1 led flashing, based on value i've set "counter" be.
could give me what's wrong thinking and/or code?
unfortunately i've come across situation notice knowledge limited, , can't see why, after several google searches, i'm hoping in here might able point me in correct direction.
the application basic one: have 2 led's want flash sequentially, first one, other. should go on indefinitely.
i've gotten work while loop, if loop doesn't work, , keep 1 led flashing, based on value i've set "counter" be.
code: [select]
void setup() {
// put setup code here, run once:
pinmode(11, output);
pinmode(12, output);
}
void loop() {
// put main code here, run repeatedly:
int counter = 0;
if (counter % 2 == 0) { //if "counter" number, run segment:
digitalwrite(11, high);
delay(500);
digitalwrite(11, low);
delay(500);
++counter;
}
else { //if "counter" isn't number, run this.
digitalwrite(12, high);
delay(500);
digitalwrite(12, low);
delay(500);
++counter;
}
}
could give me what's wrong thinking and/or code?
at start of each loop, you're putting counter 0.
move counter variable declaration outside of loop it's set 0 once, counting business can proceed.
i'd move counter++ (and correct form, ++ after, not before) single instance outside if else, no need 2 of them. move second delay each in same fashion.
move counter variable declaration outside of loop it's set 0 once, counting business can proceed.
i'd move counter++ (and correct form, ++ after, not before) single instance outside if else, no need 2 of them. move second delay each in same fashion.
Arduino Forum > Using Arduino > Programming Questions > Trying to understand conditions.
arduino
Comments
Post a Comment