the code in the listing below compiles and runs fine for me. Someone else tried compiling the same code with the errors listed below.
after working around the EEPROM errors, the readButton error persisted.
so i have noticed that sometimes there's an error because the function return type and function name are on separate lines. When I suggested putting them on the same line to someone else, the code compiled cleanly.
you may notice that readButton() is the 2nd function definition. It's getKey() that needs to be on one line.
you may notice the line reported in the error message is not line 99 and is a comment
is this a known bug?
cab12:99:17: error: two or more data types in declaration of 'readButton'
// button routine for normal operation
^
C:\1A_MauricesActiveData\model railway computer control\Arduino NCE CAB Greg\cab12\cab12.ino: In function 'void setCabAddr()':
cab12:143:13: error: 'EEPROM' was not declared in this scope
EEPROM.write (EE_CAB_ADDR, val);
^~~~~~
C:\1A_MauricesActiveData\model railway computer control\Arduino NCE CAB Greg\cab12\cab12.ino:143:13: note: suggested alternative: 'EECR'
EEPROM.write (EE_CAB_ADDR, val);
^~~~~~
EECR
C:\1A_MauricesActiveData\model railway computer control\Arduino NCE CAB Greg\cab12\cab12.ino: In function 'void eeDump(int)':
cab12:185:25: error: 'EEPROM' was not declared in this scope
Serial.println (EEPROM.read (addr));
^~~~~~
C:\1A_MauricesActiveData\model railway computer control\Arduino NCE CAB Greg\cab12\cab12.ino:185:25: note: suggested alternative: 'EECR'
Serial.println (EEPROM.read (addr));
^~~~~~
EECR
C:\1A_MauricesActiveData\model railway computer control\Arduino NCE CAB Greg\cab12\cab12.ino: In function 'void setup()':
cab12:262:18: error: 'EEPROM' was not declared in this scope
cabbusAddr (EEPROM.read (EE_CAB_ADDR));
^~~~~~
C:\1A_MauricesActiveData\model railway computer control\Arduino NCE CAB Greg\cab12\cab12.ino:262:18: note: suggested alternative: 'EECR'
cabbusAddr (EEPROM.read (EE_CAB_ADDR));
^~~~~~
EECR
exit status 1 two or more data types in declaration of 'readButton'
// NCE
const char version [] = "\"Cab12 0311b";
#include <EEPROM.h>
#include "cabbus.h"
#include "keypad.h"
#include "Led.h"
#define ADC4 4
#define Hb 13
#define TxEn 12
#define CabLed 11
#define EE_EMPTY 0xFF
#define EE_CAB_ADDR 1
#ifdef __AVR_MEGA__
# define DEBUG
#else
# undef DEBUG
#endif
int dbg = 0;
byte cabAddr = 0;
// ---------------------------------------------------------
// ---------------------------------------------------------
// keypad
//
// pin 6 ------> + + + +
// pin 7 ------> + + + +
// pin 8 ------> + + + +
// pin 9 ------> + + + +
//
// | | | -----------> pin 2
// | | -------------> pin 3
// | ---------------> pin 4
// -----------------> pin 5
//
// define the pins in the row and column
byte kpCols[] = { 5, 4, 3, 2 };
#define KP_COL_SIZE sizeof(kpCols)
byte kpRows[] = { 6, 7, 8, 9 };
#define KP_ROW_SIZE sizeof(kpRows)
// button translation into cab bus codes
char keyCodes [KP_ROW_SIZE] [KP_COL_SIZE] = {
#if 0
{ 0x51, 0x52, 0x53, 0x54 }, // 1, 2, 3, 4
{ 0x55, 0x56, 0x57, 0x58 }, // 5, 6, 7, 8
{ 0x59, 0x50, 0x5A, 0x5B }, // 9, 0, +, -
{ SEL, FOR, REV, ENTER }, // S, F, D, E
#else
{ F1, F2, F3, F4, }, // 1, 2, 3, 4
{ F5, F6, F7, F8, }, // 5, 6, 7, 8
{ F9, F0, FAST, SLOW }, // 9, 0, +, -
{ SEL, FOR, REV, ENTER }, // S, F, D, E
#endif
};
// button translation for values when setting cab addr
char numCodes [KP_ROW_SIZE] [KP_COL_SIZE] = {
{ '1', '2', '3', '4' },
{ '5', '6', '7', '8' },
{ '9', '0', NO_KEY, NO_KEY },
{ NO_KEY, NO_KEY, NO_KEY, ENTER },
};
// -------------------------------------
// scans for a keypress and translates using spcified tbl
static char
getKey (
char tbl [KP_ROW_SIZE] [KP_COL_SIZE] )
{
byte row = 0;
byte col = 0;
if (NO_KEY != keypad (& row, & col))
{
if (dbg) {
Serial.print ("getKey: ");
Serial.println (tbl [row][col], HEX);
}
return tbl [row][col];
}
return NO_KEY;
}
// -----------------------------------------------
// button routine for normal operation
static void
readButton ()
{
#if 0
int spd = int(analogRead (ADC4) / 8);
#else
int spd = SPD_BUTTON;
#endif
char key = getKey (keyCodes);
key = NO_KEY == key ? NO_KEY_DN : key;
// only report button presses;:w
if (NO_KEY_DN != key) {
cabbusUpdt (key, spd);
}
}
// ---------------------------------------------------------
// ---------------------------------------------------------
// *loopFunc supports different modes of operation
static void normal (void);
void (*loopFunc) (void) = normal;
// -----------------------------------------------
// read keypad to set cab addr in EEPROM
static void
setCabAddr (void)
{
static int val = 0;
char c = getKey (numCodes);
LedOn (CabLed);
if (NO_KEY != c)
{
if (ENTER == c)
{
loopFunc = normal;
EEPROM.write (EE_CAB_ADDR, val);
cabbusAddr (val);
LedOff (CabLed);
return;
}
val = (10 *val) + (c - '0');
}
}
// -----------------------------------------------
// normal mode, monitor keypad and cabbus for input
static void
normal (void)
{
readButton ();
cabbusRead ();
}
// -----------------------------------------------
// loop repeatedly perform desired mode and heartbeat
void
loop (void)
{
(*loopFunc) ();
heartbeat (Hb);
}
// ---------------------------------------------------------
// ---------------------------------------------------------
// display specified # eeprom locations
static void
eeDump (
int N)
{
Serial.println ("eeDump:");
for (int addr = 0; addr < N; addr++)
{
Serial.print (addr);
Serial.print ("\t");
Serial.println (EEPROM.read (addr));
}
}
// -----------------------------------------------
// check for button held down at startup
#define MIN_BUT_CNT 80
static void
butHold (void)
{
byte col = 0;
byte row = 0;
byte key = keyhold (&row, &col, MIN_BUT_CNT);
if (NO_KEY == key)
{
return;
}
#ifdef DEBUG
Serial.print ("butHold: ");
Serial.println (key);
#endif
// perform action dictated by button
switch (keyCodes [row][col])
{
case SEL:
loopFunc = setCabAddr;
break;
case FOR:
dbg = 1;
Serial.println ("butHold: dbg");
break;
case REV:
eeDump (10);
break;
default:
break;
}
}
// ---------------------------------------------------------
// one time actions at startup
byte ioPins [] = {Hb, CabLed };
#define NumIoPins sizeof(ioPins)
void
setup (void)
{
Serial.begin(9600);
for (uint8_t i= 0; i < NumIoPins; i++)
pinMode (ioPins[i], OUTPUT);
keypadSetup (kpCols, KP_COL_SIZE, kpRows, KP_ROW_SIZE);
#undef __AVR_MEGA__
#ifdef __AVR_MEGA__
Serial.println ("setup: MEGA using Serial 13");
# if 1
cabbusSetup (TxEn, CabLed, &Serial3, &Serial);
# else
cabbusSetup (TxEn, CabLed, &Serial3, NULL);
# endif
#else
cabbusSetup (TxEn, CabLed, &Serial, NULL);
#endif
cabbusAddr (EEPROM.read (EE_CAB_ADDR));
#ifdef DEBUG
Serial.println (version);
Serial.print ("cabbus addr: ");
Serial.println (EEPROM.read (EE_CAB_ADDR));
#endif
butHold ();
LedOn (CabLed);
delay (500);
LedOff (CabLed);
}