Hi, I am trying to create three blinking modes:
- all buttons blink at once
- buttons blink one at a time
- buttons blink in a pattern
and I am using "buttons" (touching two wires together where one is connected to 5V and one is connected to its designated pin through a resistor)
one button is supposed to go from mode to mode, and the other is supposed to terminate and restart the process with two different touches, basically a reset or on and off pin.
Here is my code, what am I doing wrong, and what do I need to do to make this work? Thanks!
const int buttonPin = 7; // the number of the pushbutton pin
int buttonPin2 = 8;
const int ledPin = 13;
int ledPin1 = 12;
int ledPin2 = 11;// the number of the LED pin
int buttonState = 0; // variable for reading the pushbutton status
int buttonCount = 0;
int buttonLast = 0;
int buttonState2 = 0; // variable for reading the pushbutton status
int buttonCount2 = 0;
int buttonLast2= 0;
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
pinMode(buttonPin2,INPUT);
Serial.begin(9600);//sets up serial port for debugging
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
buttonState2 = digitalRead(buttonPin2);
if (buttonState == 1 && buttonLast == 0)
{
buttonCount = (buttonCount + 1) % 3;
}
Serial.println(buttonCount);//reads the bug report
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if(buttonCount == 0)
{
digitalWrite(ledPin, HIGH);
delay(100); // wait for a second
digitalWrite(ledPin, LOW); // turn the LED off by making the voltage LOW
digitalWrite(ledPin1, HIGH);
delay(100); // wait for a second
digitalWrite(ledPin1, LOW); // turn the LED off by making the voltage LOW
digitalWrite(ledPin2, HIGH);
delay(100);// turn the LED on (HIGH is the voltage level) // wait for a second
digitalWrite(ledPin2, LOW); // turn the LED off by making the voltage LOW
}
if (buttonCount == 1) {
// turn LED on:
digitalWrite(ledPin, HIGH); // turn the LED on (HIGH is the voltage level)
delay(700); // wait for a second
digitalWrite(ledPin, LOW); // turn the LED off by making the voltage LOW
digitalWrite(ledPin1, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a second
digitalWrite(ledPin1, LOW); // turn the LED off by making the voltage LOW
digitalWrite(ledPin2, HIGH); // turn the LED on (HIGH is the voltage level)
delay(700); // wait for a second
digitalWrite(ledPin2, LOW); // turn the LED off by making the voltage LOW
}
if (buttonCount== 2) {
// turn LED on:
//here comes the blink from last week
digitalWrite(ledPin, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(ledPin1, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(ledPin2, HIGH); // turn the LED on (HIGH is the voltage level)
}
if (buttonState2 == 1 && buttonLast2 == 0){
buttonCount2 = (buttonCount2 + 1) % 3;
}
if (buttonCount2 == 1){
digitalWrite(ledPin, LOW);
delay (3000);
digitalWrite(ledPin1, LOW);
delay (3000);
digitalWrite(ledPin2, LOW);
delay (3000);
}
}