help with train project

I need help on why my program compiles but doesn't do anything. Can someone take a quick look in maybe have some suggestions on how to fix my program make it a little bit more simple I think I thank you

Moderator edit: Unknown .exe attachment removed.

Why did you not post your code or attach it directly to your post ?
I for one will not be downloading and running an executable file.

An EXE file! What's it supposed to run on? Not an Arduino that's for sure. And what UKHeliBob said, no way anyone in their right mind will download an EXE file.


Rob

#include <Wire.h>

#include <LiquidCrystal.h>

#include <MenuBackend.h>

#include <Keypad.h>

//keypad setup row and colums
const byte ROWS = 4;
const byte COLS = 4;
char keys [ROWS] [COLS] =
{{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}};

byte rowPins [ROWS] = {6, 4, 3, 2};
byte colPins [COLS] = {10, 9, 8, 7};

Keypad keypad = Keypad(makeKeymap (keys), rowPins, colPins, ROWS, COLS);

//Create the menu, passing in an arguements the functions to call on a use event
MenuBackend menu = MenuBackend(menuUseEvent,menuChangeEvent);

//Menu Items
MenuItem Item1 = MenuItem ("Engine-ID");// set en togine number 3456 four places
MenuItem Item2 = MenuItem ("Direction");
MenuItem Item3 = MenuItem ("Speed MPH");
MenuItem Item4 = MenuItem ("MU");
MenuItem Item5 = MenuItem ("Sound");
MenuItem Item6 = MenuItem ("Lights");
MenuItem setDelay = MenuItem ("Delay,'D');

//Pins
const int keypad_press = 0;
const int keypad_read = 0;
const int keypad_bit0 = 0;
const int keypad_bit1 = 0;
const int keypad_bit2 = 0;
const int keypad_bit3 = 0;

//const int keypad_read = 1

//char key = 'N';
int buttonState = 0;
boolean isUserInputtingData = false;

// Variables to hold our settings
char engineID [5] = ("0000");
unsigned int engineSpeed = 0;

//PINS
//const int keypad_press = 0;
//const int keypad_bit0 = 0;

//set up LCD library,
LiquidCrystal lcd (12, 11, 35, 36, 37, 38);

void setup(){
// Initialize serial port
Serial.begin(9600);
while(!Serial)
}
lcd.begin(16,2);

lcd.print("tom's Train Control");

// setup inputs from keypad
{
//set up our menus
menu.getRoot().add(Item1);
Item1.addBefore(Item6);
Item1.addAfter(Item2);
Item2.addBefore(Item1);
Item2.addAfter(Item3);
Item3.addBefore(Item2);
Item3.addAfter(Item4);
Item4.addBefore(Item3);
Item4.addAfter(Item5);
Item5.addBefore(Item4);
Item5.addAfter(Item6);
Item6.addBefore(Item5);
Item6.addAfter(Item1);

}
boolean readKeypadAgain = true;

void loop()
{
//char key = getKeypad();
//if (key !=NO_KEY)
//Serial.print(key);
// First, handle input from keypad
buttonState = digitalRead(keypad_press);
if(buttonState == HIGH){
if(readKeypadAgain == true)
readKeypadAgain == false;
// Keypad = getKeypad()

char key = keypad.getKey();
if (key !=NO_KEY)
Serial.print(key);
}

char getKeypad() {
int keyRead = 0;
int bito = 0;
int bit1 = 0;
int bit2 = 0;
int bit3 = 0;
char button;

bit0 = digitalRead(keypad_bit0);
bit1 = digitalRead(keypad_bit1);
bit2 = digitalRead(keypad_bit2);
bit3 = digitalRead(keypad_bit3);

keyRead = bit0 +(bit110) + (bit2100) + (bit31000);
}
switch (keyRead){
case 0:
button = '1' ;
break;
case 1:
button = '2' ;
break;
case 10:
button = '3' ;
break;
case 11:
button = 'A' ;
break;
case 100:
button = '4' ;
break;
case 101:
button = '5' ;
break;
case 110:
button = '6' ;
break;
case 111:
button = 'B' ;
break;
case 1000:
button = '7' ;
break;
case 1001:
button = '8' ;
break;
case 1010:
button = '9' ;
break;
case 1011:
button = 'C' ;
break;
case 1100:
button = '
' ;
break;
case 1101:
button = '0' ;
break;
case 1110:
button = '#' ;
break;
case 1111:
button = 'D' ;
break;
}
return (button);
}

else
{
readKeypadAgain = true;
keypad ='N';
}
void menuUseEvent(MenuUseEvent used)
{
isUserInputtingData = true;
}
else //if not, we're ptocessing up/down/enter

void menuChangeEvent(MenuChangeEvent changed)
}
//Output to LCD
lcd.clear();
lcd.setCursor(0,0);
lcd.print(changed.to.getName());

//Set cursor to start printing on next line
lcd.setCursor(0,1);

// Here's were we check what the current menu item is and display the associated value on the screen
if (Item1 == menu.getCurrent())
{
lcd.print(engineID);
}

i did quote for forum is this the way new at this tom
Moderator edit: Large unidentified .exe attachment removed. Again.

Actually, the CODE tags are right beside the QUOTE tags, up there above the editor. It's the # icon

Your code, as posted, does not compile.
When you try again to post your code, please follow this...

  1. Compile your code. Do not post it unless it compiles.

  2. Use the Tools->Auto Format menu item in the IDE to format your code.

  3. click in the IDE window, press Ctrl+a to select all.

  4. Press Ctrl+c to copy.

  5. In this forum editor, click the # icon above, then paste your code with Ctrl+v

case 101:
   button = '5' ;
   break;

101 in this case is one hundred and one, as in "One Hundred and One Dalmatians" not 5.

There did you get "MenuBackEnd" from it looks like PC GUI code to me!

Mark

101 in this case is one hundred and one, as in "One Hundred and One Dalmatians" not 5.

  keyRead = bit0 +(bit1*10) + (bit2*100) + (bit3*1000);

So?
(i think there's a scope issue with "keyRead", but the size of the numbers isn't a problem)

101 decimal not 101 binary. The OP seems to think 101 1000 are binary values look at the rest to the switch.

Mark

101 decimal not 101 binary.

Yes, I'm aware of that.

The OP seems to think 101 1000 are binary values look at the rest to the switch.

I've already quoted this, but it seems it bears repeating keyRead = bit0 +(bit1*10) + (bit2*100) + (bit3*1000);
Quirky and wasteful maybe, but not incorrect.

Ah, yes I see.

Mark

I need help on why my program compiles but doesn't do anything

This needs explanation.

I can spot a number of suspicious points:

MenuItem setDelay = MenuItem ("Delay,'D');

Should be:

MenuItem setDelay = MenuItem ("Delay,'D'");
buttonState = digitalRead(keypad_press);
if(buttonState == HIGH){
  if(readKeypadAgain == true) 
    readKeypadAgain == false;
    //    Keypad = getKeypad()
    
    char key = keypad.getKey();
    if (key !=NO_KEY)
    Serial.print(key);
}

Should be:(pay attention to indentation, alternatively you left out a pair of{})

buttonState = digitalRead(keypad_press);
if(buttonState == HIGH){
  if(readKeypadAgain == true)   readKeypadAgain = false;
  char key = keypad.getKey();
  if (key !=NO_KEY)  Serial.print(key);
}

The whole thing is a mess and nowhere near compiling - the function "getKeypad" appears to be embedded in "loop"

tom1947:

void setup(){

// Initialize serial port
  Serial.begin(9600);
  while(!Serial)
}
lcd.begin(16,2);
lcd.print("tom's Train Control");
// setup inputs from keypad
{

First, this is wrong. The { character need a } char to indicate the end of setup()
lcd.begin and lcd.print need to be in then setup().
So delete the } after while(!Serial) and the { after // setup...

Second, on setup() (when program start) the MCU wait for a char from Serial. You have an Arduino Leonardo?
This is only for Leonardo.

@tom1947, I like programming stuff for trains but I have no idea what your program is intended to do. If you want to get some useful assistance you will have to give a clear description of what you want it to do or (if it's not all your own code) what you think it should do.

If it compiles as you say, you should post a copy of the code that compiles and explain in detail what happens when you run it for comparison with what should happen.

...R

After the .exe's and the way the menu is being built at run time, I can't help but think the op is confused about where the code is to run!

@OP this section of the forum deals with code to run on an arduino NOT on the PC.

Mark

My first problem is with the library menubackend, the error message was not the cleared in this scope,
maybe problem with library. Will the new 1.5 version fixed the problem thanks tom any other suggestions would be helpful.

@tom1947, I think you need to go back to basics here.

A. In your first post you said your program compiled but didn't do anything.

B. Then someone else pointed out that you shouldn't be posting .exe files as attachments.

C. Then you posted some code (in quotes when it should have been in code tags) without any reference to the earlier comments that others had made.

D. Someone else pointed out that the posted code won't compile.

E. Someone wondered if the use of "MenuItem" meant that the code was really intended for a PC. (You haven't responded to that either).

So ...

Where did the .exe file come from and why did you think it might be relevant? (I'm not trying to be unkind, I'm trying to see things as you see them).

Have you code that compiles? If so please post it (between the proper code tags).
If you don't have code that compiles provide the code that is your best effort and explain what messages you get when you try to compile it.

What is the menu stuff and where has it come from? (Provide a link to it if appropriate).

You are the person who seems to have the problem but almost all the input in this thread is from others. That seems to be the wrong way round.

...R

Thank you for replying to my post I. First I found the menubackend library on the this forum under
MenuBackEnd new managment library.

Second I nead to tell you what I'm trying to do, I have a keypad and LCD. an arduino mega board
want to create a list of menus that I can scroll up and down and pick one and the asign a function
to run.
by saving input form keypad to arduino displaying on the lcd such as engine id 3457.
then send code to the receiver, by way of wifi xbee.

The received I will have a bridge circuit, mosfett chips for direction and speed, another arduino and xbee for receiving code.

code exceeds the maximum number of characters to be posted here thanks again Tom