Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: SainSmart LCD Shield on: January 31, 2013, 12:58:01 am
Just in case someone else wants to make a quiz using analog pin for the buttons I found this for help!
http://playground.arduino.cc/code/FiniteStateMachine
2  Using Arduino / Programming Questions / Re: SainSmart LCD Shield on: January 31, 2013, 12:54:21 am
Im not sure why i did not think of using a finite state machine. I learned how to implement them last semester in my digital logic class. Thank you for pointing my mind in the right direction!
3  Using Arduino / Programming Questions / Re: SainSmart LCD Shield on: January 31, 2013, 12:43:14 am
I guess what im asking is how do I reset the button so that I can have the left button used again for the nested if statement. I want the left button to equal yes and the right button to equal no.
4  Using Arduino / Programming Questions / SainSmart LCD Shield on: January 30, 2013, 09:32:44 pm
Hello all I am new to the arduino world and I am having a terrible time with this code any input would be great! I am just trying to make a simple quiz and I have the LCD working the way I want it to the only problem I am having is on the sheild there are 6 buttons all mapped to analog pin 0. I am wanting the if statement to use the left button for yes and the right button for no all other buttons give a funny error message. What i am having issues with is when I press the left button the display shows Q1? and then immediately moves to YAY! when I have not pushed the left button a second time yet. any help would be much appreciated!

Code:
//Sample using LiquidCrystal library
#include <LiquidCrystal.h>
 

 
// select the pins used on the LCD panel
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
 
// define some values used by the panel and buttons
int lcd_key     = 0;
int adc_key_in  = 0;
#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5
 
// read the buttons
int read_LCD_buttons()
{
 adc_key_in = analogRead(0);      // read the value from the sensor
 // my buttons when read are centered at these valies: 0, 144, 329, 504, 741
 // we add approx 50 to those values and check to see if we are close
 if (adc_key_in > 1000) return btnNONE; //
 if (adc_key_in < 50)   return btnRIGHT;
 if (adc_key_in < 195)  return btnUP;
 if (adc_key_in < 380)  return btnDOWN;
 if (adc_key_in < 555)  return btnLEFT;
 if (adc_key_in < 790)  return btnSELECT;
 return btnNONE;
}
 
void setup()
{
 lcd.begin(16, 2);              // start the library
 lcd.setCursor(0,0);
 lcd.print("greetings"); // print a simple message
 delay (2000);
 lcd.clear();
 lcd.print ("Q0?");
}
 
void loop()
{

 lcd.setCursor(9,1);            // move cursor to second line "1" and 9 spaces over
 lcd.setCursor(0,1);            // move to the begining of the second line
 lcd_key = read_LCD_buttons();  // read the buttons
 
   if (lcd_key == btnLEFT)
     {
     lcd.clear();
     lcd.setCursor(0,0);
     lcd.print("Q1?");
         if (lcd_key==btnLEFT)
           {
            lcd.clear();
            lcd.setCursor(0,0);
           lcd.print("YAY!");
            }
     }
   }
Pages: [1]