/00000000 Libraries included 00000000/
#include <SerialGraphicLCD.h>
#include <SoftwareSerial.h>
/00000000 GLCD screen size 00000000/
#define maxX 127//159
#define maxY 63 //127
/00000000 variables for PINS 00000000/
//Bup Bdown Bleft Bright Bcenter But1 But2 But3
const int buttonPin[8]={4,5,6,7,8,9,10,11};
const int ledPin13 = 13; // the number of the LED pin
/00000000 variables for debounce 00000000/
//Bup Bdown Bleft Bright Bcenter But1 But2 But3
int buttonNumber[8]={0,1,2,3,4,5,6,7};
int buttonState[8];
int lastButtonState[8]={HIGH,HIGH,HIGH,HIGH,HIGH,HIGH,HIGH,HIGH};
long lastDebounceTime[8];
long debounceDelay[8]={10,10,10,10,10,10,10,10};
int reading[8];
int ledState=LOW; // the current state of the output pin
/00000000 buttonlook variables for buttons 00000000/
int buttonlook[8]={0,0,0,0,0,0,0,0}; //variables to store if button is pressed for pin10
/00000000 variables for menus 00000000/
int menustack[6]={1,0,0,0,0,0}; //array acting as stack for menu porder when hopping from one menu to the other.
// set array size to number of menus desired
int currentmenuspot=1;
int prevmenuspot=1;
int menustackspot=0;
int menunumber;
int menupage=0; //0=Mainmenu 1=AirQ 2=TEMP 3=HEART 4=MORE
int optionrow[4][4]={{11,12,13,14},{21,22,23,24},{31,32,33,34},{41,42,43,44}}; //2D array as a map for menu options
int optionspotx=0;
int optionspoty=0;
int enterbuttons[4]={0,0,0,0}; //debounce puts a 1 to be later tested if button was pressed 1=pressed 0=not pressed
/00000000 LCD class declaration 00000000/
LCD LCD;
/00000000 SETUP 00000000/
void setup()
{
pinMode(buttonPin[0], INPUT); //button on pin 4
pinMode(buttonPin[1], INPUT); //button on pin 5
pinMode(buttonPin[2], INPUT); //button on pin 6
pinMode(buttonPin[3], INPUT); //button on pin 7
pinMode(buttonPin[4], INPUT); //button on pin 8
pinMode(buttonPin[5], INPUT); //button on pin 9
pinMode(buttonPin[6], INPUT); //button on pin 10
pinMode(buttonPin[7], INPUT); //button on pin 11
pinMode(ledPin13, OUTPUT); // pin 13 on board LED
LCD.setBacklight(20);
LCD.clearScreen();
LCD.setHome();
LCD.printStr(" Program starts in "); //displays "program is starting in 10/9/8 etc"
for(int i = 5; i >= 0; i--) //splash screen
{
LCD.setX(113);
LCD.setY(0);
LCD.printNum(i);
delay(500);
}
LCD.clearScreen();
delay(500);
}
/00000000 LOOP 00000000/
void loop()
{
selectmove(); //retrieves states of buttons to see if they were pressed
optionrowdisplay(); //display if buttons were pressed
}
/00000000 displays when buttons are pressed 00000000/
void optionrowdisplay()
{
LCD.setHome();
LCD.printStr("x spot ");
delay(50);
LCD.setX(50);
LCD.setY(00);
LCD.printNum(optionspotx);
delay(50);
LCD.setX(0);
LCD.setY(9);
LCD.printStr("y spot ");
delay(50);
LCD.setX(50);
LCD.setY(9);
LCD.printNum(optionspoty);
delay(50);
LCD.setX(0);
LCD.setY(18);
LCD.printStr("center but ");
delay(50);
LCD.setX(70);
LCD.setY(18);
LCD.printNum(enterbuttons[1]);
delay(50);
LCD.setX(0);
LCD.setY(27);
LCD.printStr("button 1 ");
delay(50);
LCD.setX(70);
LCD.setY(27);
LCD.printNum(enterbuttons[0]);
delay(50);
}
void selectmove()
{
for(int i=0; i<8; i++)
{
cleardebounce(); //clears debounces variables
debounce(buttonNumber*); //debounces input pins*
if(buttonlook*==1) //loops through all the pins*
{
* switch(i)*
* {*
* case 0: //action for when Bup button is pressed*
* if(optionspoty!=3)*
* {*
* optionspoty=optionspoty+1;*
* }*
* break;*
* case 1: //action for when Bdown button is pressed*
* if(optionspoty!=0)*
* {*
* optionspoty=optionspoty-1; *
* }*
* break;*
* case 2: //action for when Bleft button is pressed*
* if(optionspotx!=0)*
* {*
* optionspotx=optionspotx-1;*
* }*
* break;*
* case 3: //action for when Bright button is pressed*
* if(optionspotx!=3)*
* {*
* optionspotx=optionspotx+1;*
* }*
* break;*
* case 4: //action for when Bcenter button is pressed*
* enterbuttons[0]=1;*
* break;*
* case 5: //action for when But1 button is pressed*
* enterbuttons[1]=1;*
* break;*
* case 6: //action for when But2 button is pressed*
* enterbuttons[2]=1;*
* break;*
* case 7: //action for when But3 button is pressed*
* enterbuttons[3]=1;*
* break;*
* }*
}
}
}
/00000000 debounce functions 00000000/
void cleardebounce() //clears variables so that they may be retested. Must be called before each debounce.
{
* for(int i=0; i<7; i++)*
* {*
_ buttonlook*=0;
}*_
* for(int i=0; i<3; i++)*
* {*
_ enterbuttons*=0;
}
}
/00000000 debounce 00000000/
int debounce(int buttonNumber) //recieves a pin and debounces that pin
{
reading[buttonNumber] = digitalRead(buttonPin[buttonNumber]);
if (reading[buttonNumber] != lastButtonState[buttonNumber])
{lastDebounceTime[buttonNumber] = millis();}*_
* if ((millis() - lastDebounceTime[buttonNumber]) > debounceDelay[buttonNumber])*
* {*
* if (reading[buttonNumber] != buttonState[buttonNumber])*
* {*
* buttonState[buttonNumber] = reading[buttonNumber];*
* if (buttonState[buttonNumber] == LOW)*
* {*
* ledState = !ledState;*
* buttonlook[buttonNumber]=1; //changes variable to 1 to be later tested if true*
* }*
* }*
* }*
* // set the LED:*
* digitalWrite(ledPin13, ledState);// lights the LED so you know button was pressed*
* // save the reading. Next time through the loop,*
* // it'll be the lastButtonState:*
* lastButtonState[buttonNumber] = reading[buttonNumber];*
}
GLCD_first_demo_v7.ino (5.78 KB)