One flashing led in while loop and three flashing led's in three for loops.
hi all,
at moment, have red, yellow, green, , blue led's.three running @ 5 flashes each through 3 loops , red colour flashing in each of 3 loops because red typed each of 3 loops. exercise, trying keep 3 different led's running 5 flashes in 3 loops , red led through while loop flash none stop in same sketch. can show me how while loop written keep red led flashing @ times.
please see working attached sketch.
thank in advance.
at moment, have red, yellow, green, , blue led's.three running @ 5 flashes each through 3 loops , red colour flashing in each of 3 loops because red typed each of 3 loops. exercise, trying keep 3 different led's running 5 flashes in 3 loops , red led through while loop flash none stop in same sketch. can show me how while loop written keep red led flashing @ times.
please see working attached sketch.
thank in advance.
code: [select]
int redledpin = 9;
int yellowledpin = 10;
int blueledpin = 11;
int greenledpin = 12;
int redontime = 250; // red led never goes off in while
int redofftime = 250;
int yellowontime = 250;
int yellowofftime = 250;
int blueontime = 250;
int blueofftime = 250;
int greenontime = 250;
int greenofftime = 250;
int numredblink = 5;
int numyellowblink = 5;
int numblueblink = 5;
int numgreenblink = 5;
void setup() {
serial.begin(115200);
pinmode(redledpin, output);
pinmode(yellowledpin, output);
pinmode(blueledpin, output);
pinmode(greenledpin, output);
}
void loop() {
(int j = 1; j <= numyellowblink; j = j + 1) {
digitalwrite(yellowledpin, high);
digitalwrite(redledpin , high);
delay(yellowontime);
digitalwrite(yellowledpin, low);
digitalwrite(redledpin, low);
delay(yellowofftime);
}
(int k = 1; k <= numgreenblink; k = k + 1) {
digitalwrite(greenledpin, high);
digitalwrite(redledpin, high);
delay(greenontime);
digitalwrite(greenledpin, low);
digitalwrite(redledpin, low);
delay(greenofftime);
}
(int k = 1; k <= numblueblink; k = k + 1) {
digitalwrite(redledpin, high);
digitalwrite(blueledpin, high);
delay(blueontime);
digitalwrite(redledpin, low);
digitalwrite(blueledpin, low);
delay(blueofftime);
}
}
throw away loops , while loops , figure out how let loop function looping , done if statements. no loops , no delay. when there can anything. you're wasting time learning write blocking code in loops. make things harder on later when have unlearn that.
Arduino Forum > Topics > Robotics (Moderator: fabioc84) > One flashing led in while loop and three flashing led's in three for loops.
arduino
Comments
Post a Comment