I'm working on a project to help me learn how to use arduino. My project is 'supposed to' remember when I push a button, how long said button is pushed, and the length between button presses; then it is supposed to replay the eight button push sequence.
summarized... it doesn't work.
could someone please explain to me what's wrong with my code.
int ledPin = 12;
int buttonPin = 2;
int firstPress = 0;
int firstDelay = 0;
int secondPress = 0;
int secondDelay = 0;
int thirdPress = 0;
int thirdDelay = 0;
int forthPress = 0;
int forthDelay = 0;
int fifthPress = 0;
int fifthDelay = 0;
int sixthPress = 0;
int sixthDelay = 0;
int seventhPress = 0;
int seventhDelay = 0;
int eighthPress = 0;
int eighthDelay = 0;
void setup(){
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop(){
delay(1000);
if(buttonPin == HIGH){
for(; buttonPin == LOW; firstPress++){
delay(1);
}
for(; buttonPin == HIGH; firstDelay++){
delay(1);
}
for(; buttonPin == LOW; secondPress++){
delay(1);
}
for(; buttonPin == HIGH; secondDelay++){
delay(1);
}
for(; buttonPin == LOW; thirdPress++){
delay(1);
}
for(; buttonPin == HIGH; thirdDelay++){
delay(1);
}
for(; buttonPin == LOW; forthPress++){
delay(1);
}
for(; buttonPin == HIGH; forthDelay++){
delay(1);
}
for(; buttonPin == LOW; fifthPress++){
delay(1);
}
for(; buttonPin == HIGH; fifthDelay++){
delay(1);
}
for(; buttonPin == LOW; sixthPress++){
delay(1);
}
for(; buttonPin == HIGH; sixthDelay++){
delay(1);
}
for(; buttonPin == LOW; seventhPress++){
delay(1);
}
for(; buttonPin == HIGH; seventhDelay++){
delay(1);
}
for(;buttonPin == LOW; eighthPress++){
delay(1);
}
for(; buttonPin == HIGH; eighthDelay++){
delay(1);
}
digitalWrite(ledPin, HIGH);
delay(firstPress);
digitalWrite(ledPin, LOW);
delay(firstDelay);
digitalWrite(ledPin, HIGH);
delay(secondPress);
digitalWrite(ledPin, LOW);
delay(secondDelay);
digitalWrite(ledPin, HIGH);
delay(thirdPress);
digitalWrite(ledPin, LOW);
delay(thirdDelay);
digitalWrite(ledPin, HIGH);
delay(forthPress);
digitalWrite(ledPin, LOW);
delay(forthDelay);
digitalWrite(ledPin, HIGH);
delay(fifthPress);
digitalWrite(ledPin, LOW);
delay(fifthDelay);
digitalWrite(ledPin, HIGH);
delay(sixthPress);
digitalWrite(ledPin, LOW);
delay(sixthDelay);
digitalWrite(ledPin, HIGH);
delay(seventhPress);
digitalWrite(ledPin, LOW);
delay(seventhDelay);
digitalWrite(ledPin, HIGH);
delay(eighthPress);
digitalWrite(ledPin, LOW);
delay(eighthDelay);
firstPress = 0;
firstDelay = 0;
secondPress = 0;
secondDelay = 0;
thirdPress = 0;
thirdDelay = 0;
forthPress = 0;
forthDelay = 0;
fifthPress = 0;
fifthDelay = 0;
sixthPress = 0;
sixthDelay = 0;
seventhPress = 0;
seventhDelay = 0;
eighthPress = 0;
eighthDelay = 0;
}
}
Thanks a ton.
-Me