Hi! I am new to arduino and have a small sketch to help me learn. My issue is my Switch Statement gives me an error. What could I be missing? Thanks!
I am using the switch case method, because I need to learn this for another program I am working on. IF / ELSE won't work for that. And the button array needs to be a byte array as well, I can't change that.
The EEPROM portion of my code is NOT in here. I don't want to go any further until I get switch working.
#include <LiquidCrystal.h>
#include <EEPROM.h>
/// VERY SIMPLE PROGRAM
///
/// PRESS A BUTTON IN THE BUTTON ARRAY
///
/// LCD PRINTS OUT WHAT BUTTON YOU PRESSED HOPEFULLY! =)
///
/// LCD PRINTS OUT THE ADDRESS OF THE BUTTON 0 - 7 HOPEFULLY =)
///
///
byte buttons[] = {22, 26, 30, 34, 38, 42, 46, 50}; /// ARRAY OF BUTTONS , PINS OF ARDUINO 2560
byte leds[] = {20, 19, 18, 17, 16, 15, 14, 2}; /// ARRAY OF LEDS , PINS OF ARDUINO 2560
int buttonCount = 8; /// AMOUNT OF ITEMS IN ARRAY << --- MIGHT NOT BE NEEDED CODE ????
int ledsCount = 8; /// AMOUNT OF LEDS IN ARRAY << --- MIGHT NOT BE NEEDED CODE ???
LiquidCrystal lcd(12, 11, 10, 9, 8, 7); /// LCD PINS
void setup()
{
lcd.begin(16,2);
lcd.print("OOMPA LOOMPA");
delay(2000);
lcd.clear();
for ( int b=0; b<buttonCount; b++)
{
pinMode(buttons[b], INPUT); /// SETUP ARRAY OF BUTTONS AS INPUTS
digitalWrite(buttons[b], LOW); /// SETUP ARRAY OF BUTTONS AS LOW ---- NO LEDS ON AT START
}
for (int l=0; l<ledsCount; l++)
{
pinMode(leds[l], OUTPUT); /// SETUP ARRAY OF LED PINS, OUTPUT
digitalWrite(leds[l], LOW); /// PINS LOW, OFF UNTIL BUTTONS PRESSED
}
}
void loop()
{
/// SELECTING EVENTS WITH BUTTON PRESSES
switch byte(buttons[])
{
case 0:
if (buttons[0] == HIGH)
{
digitalWrite(leds[0], HIGH);
lcd.print("Button: ", buttons[0]); /// PRINT THE BUTTON NUMBER THAT IS PRESSED
lcd.print("EEPROM: "); /// BIT TO BE WRITTEN TO ADDRESS
break;
}
case 1:
if (buttons[1] == HIGH)
{
digitalWrite(leds[1], HIGH)
lcd.print("Button: ", buttons[1]) /// PRINT THE BUTTON NUMBER THAT WAS PRESSED
lcd.print("EEPROM: "); /// BIT TO BE WRITTEN TO ADDRESS
break;
}
case 2:
if (buttons[2] == HIGH)
{
digitalWrite(leds[2], HIGH);
lcd.print("Button: ", buttons[2]);
lcd.print("EEPROM: ");
break;
}
case 3;
if (buttons[3] == HIGH)
{
digitalWrite(leds[3], HIGH);
lcd.print("Button: ", buttons[3]);
lcd.print("EEPROM: ");
break;
}
case 4:
if (buttons[4] == HIGH)
{
digitalWrite(leds[4], HIGH);
lcd.print("Button: ", buttons[4]);
lcd.print("EEPROM: ");
break;
}
case 5:
if (buttons[5] == HIGH)
{
digitalWrite(leds[5], HIGH)
lcd.print("Button: ", buttons[5]);
lcd.print("EEPROM: ");
break;
}
case 6:
if buttons[6] = HIGH
{
digitalWrite(leds[6], HIGH);
lcd.print("Butons: ", buttons[6]);
lcd.print("EEPROM: ");
break;
}
case 7:
if (buttons[7] == HIGH)
{
digitalWrite(leds[7], HIGH);
lcd.print("Button: ", buttons[7]);
lcd.print("EEPROM: ");
break;
}
return -1; /// MULTIPLE BUTTON PRESSED RETURN ERROR. <<--- IS THIS WRONG ?
}
}