Reputation: 11
Its suppose to princh each time the led blinks in the serial plotter/command box like 1 2 3 4 5 but it only shows 10 the total blinks
int ledPin = 11;
int blinkTime = 700;
int timesBlinked = 0;
void setup()
{
pinMode(11, OUTPUT);
blinkyBlinky(10, blinkTime); // 10 is number of blinks, blinkTime is the milliseconds in each state from above: int blinkTime = 500;
Serial.begin(9600);
Serial.print(timesBlinked, DEC);
timesBlinked++;
Serial.setTimeout(500);
}
void loop()
{
}
void blinkyBlinky(int repeats, int time){
for (int i = 0; i < repeats; i++)
{
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
Serial.println(timesBlinked, DEC);
timesBlinked++;
}
}
for command has to be used
Upvotes: 1
Views: 50
Reputation: 16453
You called
blinkyBlinky(10, blinkTime);
before
Serial.begin(9600);
You can't write with
Serial.println(timesBlinked, DEC);
before
Serial.begin(9600);
was called.
Swap the lines in setup
:
void setup()
{
pinMode(11, OUTPUT);
Serial.begin(9600);
blinkyBlinky(10, blinkTime); // 10 is number of blinks, blinkTime is the milliseconds in each state from above: int blinkTime = 500;
Serial.print(timesBlinked, DEC);
timesBlinked++;
Serial.setTimeout(500);
}
Upvotes: 1