//blink light number of button presses
int count = 0;
const int ledPin = 13; // the number of the LED pinconst int buttonPin = 7; int buttonState = 0;
void setup() {
Serial.begin(9600);
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
}
void loop(){
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
count++;
doBlink(count); //method for blinking
delay(200);
}
if(buttonState ==LOW){
// turn LED off:
digitalWrite(ledPin, LOW); }
Serial.println(count);
if(count>7){
count = 0; }
}
//pass button presses as arguments for number of blinks:
void doBlink(int aa){
for(int i =0;i
//write a for loop, but this is a for loop while i is less than aa
delay(200);
digitalWrite(ledPin, HIGH);
delay(200);
digitalWrite(ledPin, LOW);
}
}
No comments:
Post a Comment