Show Posts
Pages: [1]
1  Forum 2005-2010 (read only) / Syntax & Programs / Re: Menu Driven Program on: January 22, 2011, 09:07:21 am
Cheers for the code!

Trying to make my own adaptation to this, but not going very well so far smiley-sad
2  Forum 2005-2010 (read only) / Frequently-Asked Questions / Yet another LCD Menu Question. on: January 22, 2011, 09:07:34 am
Hey guys,

I've been looking at loads of examples and i just cant get my head around them, calling different .h files and bits and pieces.

I want to put an LCD Screen and a 3 Button menu in my car.
i have a 16x2 LCD and 3 Large Tactile Switches all connected to the arduino, buttons are connected to Digital Input 8,9,10 and have 4 delays connected to 1,6,7 and 13.

Simple Menu:
--------------------------------
|First
|Second
|Third
|Fouth
--------------------------------

Button 1 = Up
Button 2 = Select
Button 3 = Down

All i want to do is to be able to select an option and turn a relay on and to select it again to turn it off. smiley

I Used this http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1273469106/all to try and make i work and its gone all to pot, any chance anyone could have a look at it please ?

Yeah i am a newbie, altho i should walk before i should run, but any help would be really appriciated?

Many Thanks smiley

This is my altered code:


#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int rly1Pin =  6;
int rly2Pin =  7;
int rly3Pin =  13;
int rly4Pin =  1;
int prognumber = 1;
int line = 1;

int down = 8;
int select = 9;
int up = 10;

void menu();
void LCDclear();
void LCDfirst();
void LCDsecond();
void LCDmenudisplay();

void first();
void second();
void third();
void fourth();

void setup() {
  lcd.begin(16, 2);
  menu();
}

void loop() {
  //nothing to loop but is required in every sketch.
}

void LCDclear(){
  lcd.print(0xFE, BYTE);      
  lcd.clear();
}

void LCDfirst(){
  lcd.print(0xFE, BYTE);
lcd.setCursor(0, 0); // bottom left
}
void LCDsecond(){
  lcd.print(0xFE, BYTE);
lcd.setCursor(0, 1); // bottom left
}

void menu() {
  while(digitalRead(up) == HIGH or digitalRead(down) == HIGH or digitalRead(select) == HIGH){};
  delay(50);
  LCDclear();
  LCDfirst();
  if(prognumber > 1){
  prognumber--;
  }
  else{
    prognumber == 1;
  }
  LCDmenudisplay();
  LCDsecond();
  prognumber++;
  LCDmenudisplay();
  if(line == 1){
  lcd.print(0xFE, BYTE);
  lcd.print(143, BYTE);
  lcd.print("<");
  }
  else {
  lcd.print(0xFE, BYTE);
  lcd.print(207, BYTE);
  lcd.print("<");
  }
  while(digitalRead(up) == LOW && digitalRead(down) == LOW && digitalRead(select) == LOW){}
  if(digitalRead(down) == HIGH){
  line++;
  if(line > 2){
  line = 2;
  prognumber++;
  if(prognumber > 4){
  prognumber = 5;
  }
  }
  menu();
  }
  else if(digitalRead(up) == HIGH){
  line--;
  if(line < 1){
  line = 1;
  prognumber--;
  }
  menu();
  }
  else if(digitalRead(select) == HIGH){
  if(line == 1){
    prognumber--;
  }
  switch (prognumber) {                  
  case 1:                                
    first();
    break;                              
  case 2:
    second();
    break;
  case 3:
    third();
    break;
  case 4:
    fourth();
    break;
  default:
    first();
  }
  }
}

void LCDmenudisplay() {
  switch (prognumber) {                  
  case 1:                                
    lcd.print("First");  
    break;                              
  case 2:
    lcd.print("Second");
    break;
  case 3:
    lcd.print("Third");
    break;
  case 4:
    lcd.print("Fourth");
    break;
  }
  
}

void first() {
  digitalWrite(rly1Pin, HIGH);
  menu();
}

void second() {
    digitalWrite(rly2Pin, HIGH);
  menu();
}

void third() {
    digitalWrite(rly3Pin, HIGH);
  menu();
}
void fourth() {
    digitalWrite(rly4Pin, HIGH);
  menu();
}



Pages: [1]