I coudnt figure it out.. pls help
using switch case with pushbutton..
code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
const int buttonPin1 = 6;
const int buttonPin2 = 5;
const int buttonPin3 = 4;
const int buttonPin4 = 3;
const int ledPin = 13;
int prevButtonState1 = 0;
int prevButtonState2 = 0;
int prevButtonState3 = 0;
int prevButtonState4 = 0;
int buttonState = 0;
int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
void setup(){
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
pinMode(buttonPin4, INPUT);
pinMode(relay, OUTPUT);
pinMode(pulsePin, INPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
attachInterrupt(coinInt, coinInserted, RISING);
digitalWrite(pulsePin, HIGH);
digitalWrite(13, LOW);
digitalWrite(relay, LOW);
}
void loop(){
const int state = HIGH;
const int buttonState1 = digitalRead(buttonPin1);
const int buttonState2 = digitalRead(buttonPin2);
const int buttonState3 = digitalRead(buttonPin3);
switch (state){
case buttonState1:
lcd.clear();
lcd.begin(20, 4);
lcd.setCursor(0, 0);
lcd.print("Please Insert Coin");
lcd.setCursor(0, 1);
lcd.print("Amount: P0");
lcd.setCursor(0, 2);
lcd.print("Duration: 00:00");
prevButtonState1 = buttonState1;
process();
break;
case buttonState2:
lcd.clear();
lcd.begin(20, 4);
lcd.setCursor(0, 0);
lcd.print("Please Insert Coin");
lcd.setCursor(0, 1);
lcd.print("Amount: P0");
lcd.setCursor(0, 2);
lcd.print("Duration: 00:00");
prevButtonState1 = buttonState1;
break;
case buttonState3:
lcd.clear();
lcd.begin(20, 4);
lcd.setCursor(0, 0);
lcd.print("Please Insert Coin");
lcd.setCursor(0, 1);
lcd.print("Amount: P0");
lcd.setCursor(0, 2);
lcd.print("Duration: 00:00");
prevButtonState1 = buttonState1;
break;
}