-
For the delay() functions, I have excluded out the part using /*
-
For the code tags, it is found inside the switch case section.
it is displayed by //..... etc.
int buttonState = LOW;//current state of the LED
unsigned long timeOfLastLedEvent = 0;//the last time the LED was updated
boolean currentState = LOW;//stroage for current measured button state
boolean lastState = LOW;//storage for last measured button state
boolean debouncedState = LOW;//debounced button state
int debounceInterval = 20;//wait 20 ms for button pin to settle
int intervalON = 1000;//how long we want the switch to stay on
int intervalOFF = 500;//how long we want the switch to stay off
int pin11 = 11; //Define arduino pin 11
int pin = 12; //Define arduino pin 12
int buttonPin = 10; //Define button pin 10
int counter = 0; //no. of counters
boolean running = false;
int var;
void setup() {
Serial.begin(9600);
pinMode(pin11, OUTPUT);
digitalWrite(11, buttonState);
pinMode(pin, OUTPUT);
digitalWrite(pin, buttonState);
pinMode(buttonPin, INPUT);
switch (var) {
case 1:
digitalWrite(11, LOW);
digitalWrite(12, LOW);
Serial.print("0");
Serial.println("0");
break;
//This is to display that if I pressed the push button once, on the Serial Monitor, it will display (0,0) only once.
case 2:
digitalWrite(11, LOW);
digitalWrite(12, HIGH);
Serial.print("0");
Serial.println("1");
break;
//This is to display that if I pressed the push button 2 times, on the Serial Monitor, it will display (0,1) only once.
case 3:
digitalWrite(11, HIGH);
digitalWrite(12, LOW);
Serial.print("1");
Serial.println("0");
break;
//This is to display that if I pressed the push button 3 times, on the Serial Monitor, it will display (1,0) only once.
case 4:
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
Serial.print("1");
Serial.println("1");
break;
//This is to display that if I pressed the push button 4 times, on the Serial Monitor, it will display (1,1) only once.
default:
break;
//And if I pressed the push button once, it will return back to (0,0) and the loop continues
}
}
void loop()
{
//Handle input
buttonState = digitalRead(buttonPin);
if(buttonState == HIGH)
{
counter++;
//Reset count if over max mode number
if(counter == 5)
{
counter = 0;
}
}
}
/*{
if(counter == 1)
{
digitalWrite(11, LOW);
digitalWrite(12, LOW);
Serial.print("0");
Serial.println("0");
delay(1000); // delay to debounce switch
running = !running; // toggle running variable
digitalWrite(buttonPin, running); // indicate via buttonPin
}
else if(counter == 2)
{
digitalWrite(11, LOW);
digitalWrite(12, HIGH);
Serial.print("0");
Serial.println("1");
delay(1000); // delay to debounce switch
running = !running; // toggle running variable
digitalWrite(buttonPin, running); // indicate via buttonPin
}
else if(counter == 3)
{
digitalWrite(11, HIGH);
digitalWrite(12, LOW);
Serial.print("1");
Serial.println("0");
delay(1000); // delay to debounce switch
running = !running; // toggle running variable
digitalWrite(buttonPin, running); // indicate via buttonPin
}
else if(counter == 4)
{
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
Serial.print("1");
Serial.println("1");
delay(1000); // delay to debounce switch
running = !running; // toggle running variable
digitalWrite(buttonPin, running); // indicate via buttonPin
}
}
{
unsigned long currentMillis = millis();
currentState = digitalRead(buttonPin);
unsigned long currentTime = millis();
if (buttonState == LOW){//if the buttonPin is already off
if (currentMillis - timeOfLastLedEvent > intervalOFF){//and enough time has passed
digitalWrite(pin11, HIGH);//turn it on
buttonState = HIGH;//store its current state
timeOfLastLedEvent = currentMillis;//update the time of this new event
}
} else {//if the buttonPin is already on
if (currentMillis - timeOfLastLedEvent > intervalON){
digitalWrite(pin, LOW); //turn it off
buttonState = LOW;
timeOfLastLedEvent = currentMillis;
}
}
}
}
*/