Go Down

Topic: Scrolling menu program hangs... (Read 2871 times) previous topic - next topic

mowcius

Code: [Select]
#include <NewSoftSerial.h>

NewSoftSerial LCDserial(0, 2);

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 fifth();

void setup() {
 LCDserial.begin(9600);
}

void loop() {
 menu();
}

void LCDclear(){
 LCDserial.print(0xFE, BYTE);
 LCDserial.print(0x01, BYTE);
}

void LCDfirst(){
 LCDserial.print(0xFE, BYTE);
 LCDserial.print(128, BYTE);
}
void LCDsecond(){
 LCDserial.print(0xFE, BYTE);
 LCDserial.print(192, BYTE);
}

void menu() {
 while(digitalRead(up) == HIGH || digitalRead(down) == HIGH || digitalRead(select) == HIGH){};
 LCDclear();
 LCDfirst();
 if(prognumber > 1){
   prognumber--;
 }
 else{
   prognumber = 1;
 }
 LCDmenudisplay();
 LCDsecond();
 prognumber++;
 LCDmenudisplay();
 if(line == 1){
   LCDserial.print(0xFE, BYTE);
   LCDserial.print(143, BYTE);
   LCDserial.print("<");
 }
 else {
   LCDserial.print(0xFE, BYTE);
   LCDserial.print(207, BYTE);
   LCDserial.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;
     }
   }
 }
 else if(digitalRead(up) == HIGH){
   line--;
   if(line < 1){
     line = 1;
     prognumber--;
   }
 }
 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;
   case 5:
     fifth();
     break;
   default:
     first();
   }
 }
 delay(50);
}

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

}

void first() {
 digitalWrite(13, HIGH);
}

void second() {
 digitalWrite(13, HIGH);
 delay(1000);
 digitalWrite(13, LOW);
 delay(1000);
 digitalWrite(13, HIGH);
 delay(1000);
 digitalWrite(13, LOW);
}

void third() {
 digitalWrite(13, HIGH);
 delay(500);
 digitalWrite(13, LOW);
 delay(500);
 digitalWrite(13, HIGH);
 delay(500);
 digitalWrite(13, LOW);
}

void fourth() {
 digitalWrite(13, HIGH);
 delay(100);
 digitalWrite(13, LOW);
 delay(100);
 digitalWrite(13, HIGH);
 delay(100);
 digitalWrite(13, LOW);
}

void fifth() {
 digitalWrite(13, LOW);
}  


As I never posted up the completely correct code before.  :P

madepablo

I never used it, but here is a menu library:

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1240415211

May be could be useful to you.

Cheers,

mowcius

I have seen that library but it did not do what I wanted it to  ;)

So I wrote some code that did   :D

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy