Hi,
Still working on the DCC++ Throttle.
The code is heavily customized and working using an Arduino Uno.
Now I want to use an Arduino Nano and everything works except getting the loco address. (without this function the rest is useless)
I should be able to input commands using a keypad (3x4)
When “*” is pushed the display should display “Set Dcc Addr #” displayed, after that the user should enter the address using the same keypad.
Does anybody know why this piece of code doesn’t run on the Nano?
When “*” is pushed the track power is shut off (Serial.print("<0>"); does that but after that nothing new is displayed.
void getLocoAddress() {
Serial.print("<0>"); // track power off to DCC++ unit
int total = 0;
counter = 0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Set Dcc Addr # ");
lcd.print(ActiveAddress + 1);
do {
TrigVal2 = digitalRead(Trigger2); // read the input pin
if (TrigVal2 == 0) break; // exit routine if right button pressed - ABORT new address
key = keypad.getKey();
if (key) {
counter++;
int number = key - 48;
total = total * 10 + number;
lcd.setCursor(0, 1);
if (total == 0) { // print multiple zeros for leading zero number
for (int tempx = 1; tempx <= counter; tempx++) {
lcd.print("0");
}
}
else lcd.print(total);
}
TrigVal2 = digitalRead(Trigger2); // read the input pin
}
while (counter <= 3); // collect exactly 4 digits
LocoAddress[ActiveAddress] = total;
saveAddresses();
lcd.clear();
doMainLCD();
}
Is there something in this piece of code that a Nano can’t handle?
A total of 4 addresses are stored in the EEPROM.
EDIT:
I have added "delay(2000); to the code after "lcd.print("Set Dcc Addr # “);”
When “*” is pushed “Set Dcc Addr #” is displayed for 2 seconds so pushing the button calls the code but it doesn’t wait for input???
Please see the entire code attached.
Throttle_DCCpp_Leo.ino (14.6 KB)