Here is my code. The purpose of this code is to have it read the "if" statements a certain amount of times, in this case 11 times, and once it has reached a certain loop count, to have it shut off. I implemented the "while" statement to make that happen but it instead takes my count for the if statements and starts it at 13.
int led = 12;
int led1 = 11;
int cnt = 1;
int del;
void setup() {
// put your setup code here, to run once:
Serial.begin (9600);
pinMode (led,OUTPUT);
pinMode (led1,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
{
{ while (cnt <=11) cnt++;}{
if (cnt <= 3 and cnt > 0) {del = 1500;}
if (cnt > 3 and cnt <= 6) {del = 1000;}
if (cnt > 6 and cnt <= 9) { del = 500;}
if (cnt > 9 and cnt <= 12) {del = 250;}
if (cnt > 12 and cnt <= 15) { del = 125;}
if (cnt > 15 and cnt <= 18) {del = 1000;}
if (cnt > 18 and cnt <= 21) { del = 500;}
if (cnt > 21 and cnt <= 24) {del = 250;}
if (cnt > 24 and cnt <= 27) { del = 125;}
if (cnt == 27) {cnt = 1;}
}
}
digitalWrite (led, HIGH); //Turn on red LED
delay(del);
digitalWrite (led, LOW); //Turn off green LED
delay (del); //Delay
digitalWrite (led1, HIGH); //Turn on green LED
delay(del);
digitalWrite (led1, LOW); //Turn off red LED
delay (del); //Delay
cnt++; //Add count
Serial.println(cnt); //To read count