HI
I'm new to the forum and Arduino software and I've been working on some code cycling up and down 4 relays and toggling an Led on and off from a 4 x 1 keypad with reference to Gnd as I'm using internal pullups and the Arduino Mega.
It worked ok until i added code for the left and right keys and now i cant get it to compile and i cant seem to clear the errors and wondered if anyone could take a look at all and try to get it to compile. Thanks
//4 Aspect CLS controller
//RD
//V1.1
//keys
//left = aspect Down
//Down = aspect off
//UP = Aspect ON
//Right = aspect UP
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
const int inPinRight = A12;
const int inPinLft = A11
const int inPinUp = A13;
const int inPinDown = A14;
int Aspect = 0;
int buttonUpState = 0;
int buttonDownState = 0;
int buttonRightState = 0;
int buttonLeftState = 0
int prevBtnUp = LOW;
int prevBtnDwn = LOW;
int prevBtnRgt = LOW;
int prevBtnLft = LOW;
unsigned long lastBtnUp = 0;
unsigned long lastBtnDwn = 0;
unsigned long lastBtnRgt = 0,
unsigned long lastBtnLft = 0;
int DebounceTime = 100;
int Out1 = 24;
int Out2 = 25;
int Out3 = 26;
int Out4 = 27;
int Out5 = A0;
void setup()
{
pinMode(inPinUp, INPUT_PULLUP);
pinMode(inPinDown, INPUT_PULLUP);
pinMode(inPinRight, INPUT_PULLUP);
pinMode(inPinleft, INPUT_PULLUP);
pinMode(Out1, OUTPUT);
pinMode(Out2, OUTPUT);
pinMode(Out3, OUTPUT);
pinMode(Out4, OUTPUT);
pinMode(Out5, OUTPUT);
digitalWrite(Out1, HIGH); //initial state
digitalWrite(Out2, HIGH);
digitalWrite(Out3, HIGH);
digitalWrite(Out4, HIGH);
digitalWrite(Out5, HIGH);
lcd.begin(16, 2);
lcd.print("CLS R-Y-G-YY");
}
void AspectFunction() {
switch (Aspect) {
case 1:
lcd.setCursor(2, 1);
lcd.print("RED ");
digitalWrite(Out1, LOW);
digitalWrite(Out2, HIGH);
digitalWrite(Out3, HIGH);
digitalWrite(Out4, HIGH);
break;
case 2:
lcd.setCursor(0, 1);
lcd.print("YELL ");
digitalWrite(Out1, HIGH);
digitalWrite(Out2, LOW);
digitalWrite(Out3, HIGH);
digitalWrite(Out4, HIGH);
break;
case 3:
lcd.setCursor(0, 1);
lcd.print("GREEN ");
digitalWrite(Out1, HIGH);
digitalWrite(Out2, HIGH);
digitalWrite(Out3, LOW);
digitalWrite(Out4, HIGH);
break;
case 4:
lcd.setCursor(0, 1);
lcd.print("YELL-YELL");
digitalWrite(Out1, HIGH);
digitalWrite(Out2, LOW);
digitalWrite(Out3, HIGH);
digitalWrite(Out4, LOW);
break;
}
}
void loop() {
buttonUpState = digitalRead(inPinUp);
buttonDownState = digitalRead(inPinDown);
buttonRightState = digitalRead(inPinRight);
buttonLeftState = digitalRead(inPinLeft);
//Up Button
if (buttonUpState == HIGH && prevBtnUp == LOW)
{
if (millis() - lastBtnUp > DebounceTime)
{
digitalWrite(Out1, HIGH); //new
digitalWrite(Out2, HIGH);
digitalWrite(Out3, HIGH);
digitalWrite(Out4, HIGH);
delay(500); // new
Aspect++;
if (Aspect > 3)
{
Aspect = 4;
}
lastBtnUp = millis();
AspectFunction();
}
}
prevBtnUp = buttonUpState;
//Down Button
if (buttonDownState == HIGH && prevBtnDwn == LOW) {
if (millis() - lastBtnDwn > DebounceTime) {
digitalWrite(Out1, HIGH); //new
digitalWrite(Out2, HIGH);
digitalWrite(Out3, HIGH);
digitalWrite(Out4, HIGH);
delay(500); // new
Aspect--;
if (Aspect < 1) {
Aspect = 1;
}
lastBtnDwn = millis();
AspectFunction();
}
}
prevBtnDwn = buttonDownState;
// Right Button
if (buttonRightState == HIGH && prevBtnRgt == LOW) {
if (millis() - lastBtnRgt > DebounceTime) {
lastBtnRgt = millis();
digitalWrite(Out5, HIGH); //void RightKey();
}
}
prevBtnRgt = buttonRightState;
}
//Left Button
if (buttonLeftState == HIGH && prevBtnLft == LOW) {
if (millis() - lastBtnLft > DebounceTime) {
lastBtnLft = millis();
digitalWrite(Out5, LOW);
}
}
prevBtnLft = buttonLeftState;
}