Pages: [1]   Go Down
Author Topic: Errors in compiling a menu user interface for serial LCD and thumb joystick  (Read 57 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello! I'm working on a school project, and I'm trying to get a navigational menu set up on a 128x64 serial LCD that's controlled by a joystick, both from Sparkfun (https://www.sparkfun.com/products/9351 and https://www.sparkfun.com/products/9032 respectively). I'm using their Redboard (https://www.sparkfun.com/products/11575) which is essentially an Arduino Uno for the microprocessor. I've had a lot of help on this code so far, so I understand the basic gist of it, but not necessarily all the specific commands. Here is what I have so far:

Code:
//set global variables
//define variables
#define lowerAnalogThresh 400
#define upperAnalogThresh 600
#define upDownPin 7

//define integers
int currentMenuPosition=1;
int topMenuOptionsNumber=3;
int HarmonicMotionOptionsNumber=3;
int EarthquakeOptionsNumber=3;

//establish menu strings for labeling
string[]topMenuOptions={"Top Menu","Harmonic Motion","Earthquakes"}
              //topMenuOptions [0],     [1],              ,[2]
string[]HarmonicMotionOptions={"Harmonic Options","Amplitude","Start","Back"}
string[]EarthquakeOptions={"Q1","Q2","Q3"}

//enum creates a new variable type so we can move from menu to menu
enum menuDepth{
  TopMenu,
  ThirdLevel}
enum TopMenu{
  EQ
  HarmMotion};
enum ThirdLevel{
  Q1,Q2,Q3, //menu under EQ
  Amp,Start}; //menu under HarmMotion
enum direction{
  UP,DOWN};
 
//something about labeling menu levels?
menuDepth _menuDepth=menuDepth.TOP;
secondLevel _secondLevel=secondLevel.HARMMOTION

void loop(){
  readJoystick();
}

//functions
void readJoystick(){
  int value=analogRead(upDownPin);
  direction dir
  bool buttonPushed=false;
  if(value>upperAnalogThresh){
    dir=direction.UP;
    while(analogRead(upDownPin)>upperAnalogThresh){}
    delay(100);
    MenuHandler(direction.UP,FALSE);
    return;
  }
  else if(value<lowerAnalogThresh){
    dir=direction.DOWN
    while(analogRead(upDownPin)<lowerAnalogThresh){}
    delay(100);
    MenuHandler(direction.DOWN,FALSE);
    return;
  }
  else if(digitalRead(buttonPin==HIGH)){
    MenuHandler(direction.UP,TRUE);
    return;
  }
}

void MenuHandler((direction_dir),(bool_buttonPushed)){
  if(_buttonPushed){
    if(_menuDepth==menuDepth.TOP){
      if(currentMenuPosition==1){
        currentMenuPosition=1;
        _menuDepth=secondLevel;
        _secondLevel==secondLevel.HARMMOTION;
        MenuHandler(HarmonicMotionOptions,HarmonicMotionOptionsNumber);
        return;
      }
      if(currentMenuPosition==2){
        currentMenuPosition=1;
        _menuDepth=secondLevel;
        _secondLevel==secondLevel.EARTHQUAKE;
        MenuHandler(EarthquakeOptions,EarthquakeOptionsNumber);
        return;
      }
    }
    if(_menuDepth==menuDepth.secondLevel){
     if(_secondLevel=secondLevel.HARMMOTION){
      if(currentMenuPosition==1){
       _menuDepth=menuDepth.third;
      _thirdLevel=thirdLevel.AMP;
      AMPMenuHandler()
      return;
      }
      if(currentMenuPosition==2){
        //start program
        //call MenuHandler
        return;
      }
      if(currentMenuPosition==3){
        _menuDepth=menuDepth.TOP;
        MenuHandler(topMenuOptions,topMenuOptionsNumber);
      }
     }
     if(_secondLevel=secondLevel.EARTHQUAKE){
       if(currentMenuPosition==1){
         //start program
         //call MenuHandler
         return;
       }
       if(currentMenuPosition==2){
         //start program
         //call MenuHandler
         return;
       }
       if(currentMenuPosition==3){
         //start program
         //call MenuHandler
         return;
       }
     }
    }
    if(_menuDepth==menuDepth.third){
      if(_thirdLevel==thirdLevel.AMP){
        if(currentMenuPosition==3){
          _menuDepth=menuDepth.secondLevel;
          currentMenuPosition=3;
          MenuHandler(HarmonicMotionOptions,HarmonicMotionOptionsNumber);
        }
      }
    }
  }
  else if(_dir=direction.UP){
    if(currentMenuPosition!=1)
    currentMenuPosition--;
  }
  else if(_dir=direction.DOWN){
    if(currentMenuPosition!=3){
      currentMenuPosition++;
    }
  }
  MenuUpdate();
}

void MenuUpdate((string[]vals),(int num)){
  //clear screen
  //set cursor to home
  for(int=0;i<num;i++){
    if(i==currentMenuPosition){
      Serial.print("->");
      Serial.pring(vals[i]);
    }
    else{
      Serial.print("  ");
      Serial.print(vals[i]);
    }
  }
}

And here are the errors I'm getting right now:
Code:
UserInterfaceEdits:11: error: expected constructor, destructor, or type conversion before 'void'
UserInterfaceEdits:14: error: expected constructor, destructor, or type conversion before 'topMenuOptions'
UserInterfaceEdits:16: error: expected constructor, destructor, or type conversion before 'HarmonicMotionOptions'
UserInterfaceEdits:17: error: expected constructor, destructor, or type conversion before 'EarthquakeOptions'
UserInterfaceEdits:25: error: expected `}' before 'HarmMotion'
UserInterfaceEdits:25: error: expected initializer before '}' token
UserInterfaceEdits:25: error: expected declaration before '}' token

Any help with these errors, or the general code, would be much appreciated!
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 547
Posts: 45987
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
string[]topMenuOptions={"Top Menu","Harmonic Motion","Earthquakes"}
              //topMenuOptions [0],     [1],              ,[2]
string[]HarmonicMotionOptions={"Harmonic Options","Amplitude","Start","Back"}
string[]EarthquakeOptions={"Q1","Q2","Q3"}
Whatsthisrubbish?

1) Fix your f***ing space key.
2) string is not a type
3) The array notation follows the name, not the type.

Code:
enum TopMenu{
  EQ
  HarmMotion};
Does the phrase comma separated values mean anything to you?

Code:
enum menuDepth{
  TopMenu,
  ThirdLevel}
Does the fact that statements need to end with semicolons mean anything to you?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24309
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
void MenuHandler((direction_dir),(bool_buttonPushed)){
Needs more types.
What language was this transcribed from?

Quote
I've had a lot of help on this code so far,
You're going to need a whole lot more- I can't believe a sketch has got so big with so many mistakes in it - you should be compiling as you go along, not just scribbling down some random syntax and hoping it will compile and eventually work.
« Last Edit: April 15, 2014, 05:04:13 am by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
you should be compiling as you go along, not just scribbling down some random syntax and hoping it will compile and eventually work

I got this code by meeting up with someone who claimed to be very knowledgeable about Arduino, and then wrote this out on a white board for me to copy and fix up. I'm not great at Arduino, still fairly new, so AWOL, would you suggest just scraping this and starting somewhere new or do you think it's salvageable?
Logged

Pages: [1]   Go Up
Jump to: