I Have a simple project that reads a 3Cx4R keypad which uses a single character lookup using Keypad.h to determine the location of the key presses. There multiple keypads used and depending on product model Key functionality in any position (rxc) may have different functions. I then have a function getKey that look for a test string that was assigned to the specific key location. I then search for the string function name and perform specific control.
The code compiles and runs fine on Arduino Nano. However simply changing the board to Arduino Nano 33 IoT the compiler fails on any use of my getKey function.
// uses the keypad row and col as index to string description of key functions.
char* getKey(char *k)
{ for(int i=0; i<16; i++) {
if(specialKeysID[i] == k) return specialKeys[i]; }
}
error: "C++ forbids comparison between pointer and integer [-fpermissive]
if(specialKeysID[i] == k) return specialKeys[i]; } "*
This error occurs on every occurrence of getKey() function call.
eg: getKey(keyPressed)
No Error message on nano and other non wifi and BT boards
Can anyone explain what is preventing this from compiling on the nano33Iot or why is is able to compile on Nano given the error message.
Complete simplified code:
// Correct software for Smart with top cable keypad s-w connection should work on PCB v2
//#define conditional compilation
// Keypad defines
//define KEYPAD_BLUE_SMALL
//#define KEYPAD_GREEN
//#define KEYPAD_PLUS
//#define KEYPAD_PHONE
//#define KEYPAD_STOP3
//#define KEYPAD_CYD
#define KEYPAD_PLUS_INVERTED
int PRESSURE = 4; // Arduino D4 - How2 PRESSURE INPUT to detect PRESSURE SW state
int count = 0; //
int FLOW = 8; // Arduino D8 - How2 HI/LO Pwr/Water connector Pin3 {Original LEDgrey}
int WATER = 9; // Arduino D9 - How2 WATER Turns Water off/on bypasses Pin8 HI/LO control affects WATER_OUT {Original LEDwhite}
int Solution_1 = 6; // Arduino D6 - HOW2 Solution_1 control for Solution_1_OUT [original LEDred]
int Solution_2 = 5; // Arduino D5 - HOW2 Solution_2 control for Solution_2_OUT {original LEDyellow}
int Solution_3 = 3; // Arduino D3 - HOW2 Solution_3 control for Solution_3_OUT [original LEDblue]
int LED = 13;
int LED_ON = HIGH;
int LED_OFF = LOW;
char* keyFunction = "";
// Time related variable declarations
int KEY_PRESS_TIME_OUT;
int tt=0;
//int D10 = 10;
int i; // itterationloop index
//void(* resetFunc) (void) = 0;
// these are the "formulas"
// 175-255 100-255
int flowRate_MAX = 255; //Originally multiple <color>LED = <value>
int flowRate_OFF = 0;
int flowRate_100 = 100;
int flowRate_125 = 125;
int flowRate_150 = 150 ;
// TIMER VARIABLES
unsigned int long time;
unsigned int long KEYPRESS_TIMER_START; //start of program
unsigned int long KEYPRESS_TIMER_NOW; //start of program
unsigned int long KEYPRESS_TIMER; //start of program
int KEYPRESSED_TIME_MAX = 10;
bool KEYPRESS_TIMEOUT = false;
/* @file CustomKeypad.pde
|| @version 1.0
|| @author Alexander Brevig
|| @contact alexanderbrevig@gmail.com
|| @description
|| | Demonstrates changing the keypad size and key values.
|| #
*/
#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
//define the symbols on the buttons of the keypads
#if defined KEYPAD_BLUE_SMALL
char* specialKeys[] = {
"200ppm Sanitizer", "400ppm Sanitizer", "Glass Cleaner",
"Restroom Cleaner", "Sink Cleaner", "Toilet Bowel Cleaner",
"All Purpose Cleaner", "Mild Cleaner", "Heavy Duty Cleaner",
"STOP", "Rinse", "ERROR"
};
#endif
#ifdef KEYPAD_GREEN
char* specialKeys[] = {
"Glass", "Floors", "Degreaser",
"Restroom LD", "Restroom MD", "Restroom HD",
"Restroom Sink", "Stop", "Toilet",
"Clean", "Rinse", "Sanitize"
};
#endif
#ifdef KEYPAD_PLUS
char* specialKeys[] = {
"Hand Soap LD", "Hand Soap MD", "Hand Soap HD",
"Glass", "Floors", "Degreaser",
"Restroom", "STOP", "Toilet",
"Clean", "Rinse", "Sanitize"
};
#endif
#ifdef KEYPAD_PLUS_INVERTED
char* specialKeys[] = {
"ERROR", "Rinse", "STOP",
"Hand Soap HD", "Hand Soap MD", "Hand Soap LD",
"Toilet", "Cleaner MD", "Cleaner LD",
"Glass", "400ppm Sanitizer", "200ppm Sanitizer"
};
#endif
#ifndef KEYPAD_PLUS_INVERTED
char specialKeysID[] = {
'1', '2', '3',
'4', '5', '6',
'7', '8', '9',
'*', '0', '#',
};
#else // inverted plus keyboard mapping
char specialKeysID[] = {
'#', '0', '*',
'9', '8', '7',
'6', '5', '4',
'3', '2', '1',
};
#endif
char keys[ROWS][COLS] = {
{specialKeysID[0], specialKeysID[1], specialKeysID[2]},
{specialKeysID[3], specialKeysID[4], specialKeysID[5]},
{specialKeysID[6], specialKeysID[7], specialKeysID[8]},
{specialKeysID[9], specialKeysID[10], specialKeysID[11]}
};
byte rowPins[ROWS] = { A3, A2, A1, A0}; //connect to the row pinouts of the keypad
byte colPins[COLS] = { 10, A5, A4}; //connect to the column pinouts of the keypad
Keypad customKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
int timeOut;
int totalTime = 2; //total time
int timeElapsed; //Time elasped
int ifDelay = 500;
// ************** SETUP CODE **************
//
void setup() {
Serial.begin(9600);
pinMode(10,OUTPUT);
digitalWrite(PRESSURE, HIGH);
delay(20);
pinMode(PRESSURE, OUTPUT);
pinMode(WATER, OUTPUT);
pinMode(FLOW, OUTPUT);
pinMode(Solution_2, OUTPUT);
pinMode(Solution_3, OUTPUT);
pinMode(Solution_1, OUTPUT);
pinMode(LED,OUTPUT);
digitalWrite(WATER, LOW);
digitalWrite(FLOW, LOW);
digitalWrite(Solution_2, LOW);
digitalWrite(Solution_3, LOW);
digitalWrite(Solution_1, LOW);
Serial.println("");
Serial.println(".....");
Serial.println("Start Scanning Keypad:\r \b\b\b\b asds");
Serial.print("");
} // end seetup
// ****************** MAIN CODE LOOP *******************
//
void loop() {
// digitalWrite(LED, LED_ON);
// delay(100);
// digitalWrite(LED,LED_OFF);
// delay(1000);
KEYPRESS_TIMEOUT = false;
KEYPRESS_TIMER_NOW = millis();
char keyPressed = customKeypad.getKey();
if (keyPressed){
KEYPRESS_TIMER_START = KEYPRESS_TIMER_NOW;
Serial.print("Key Pressed was: ");
Serial.println(keyPressed);
Serial.println(getKey(keyPressed));
Serial.println("");
}
else {
KEYPRESS_TIMEOUT = checkforKeyPresstimeOut();
}
KEYPRESS_TIMEOUT = checkforKeyPresstimeOut();
if (getKey(keyPressed) == "STOP" || KEYPRESS_TIMEOUT == true)
{
Serial.print("Dispensing stopped, waiting on keypress: "); Serial.println(KEYPRESS_TIMEOUT);
digitalWrite(FLOW, LOW);
digitalWrite(WATER, flowRate_OFF);
analogWrite(Solution_2, flowRate_OFF);
analogWrite(Solution_3, flowRate_MAX);
analogWrite(Solution_1, flowRate_OFF);
KEYPRESS_TIMER_START = KEYPRESS_TIMER_NOW;
KEYPRESS_TIMEOUT = false;
Serial.println(KEYPRESS_TIMEOUT);
}
// 1
if (getKey(keyPressed) == "200ppm Sanitizer") {
analogWrite(Solution_1, flowRate_OFF);
}
// 2
if (getKey(keyPressed) == "400ppm Sanitizer") {
//Serial.print("400ppm key presseed");
analogWrite(Solution_1, flowRate_MAX);
}
// 3
if (getKey(keyPressed) == "Glass Cleaner") {
analogWrite(Solution_3, flowRate_150);
}
// 4
if (getKey(keyPressed) == "Restroom Cleaner") {
analogWrite(Solution_3, flowRate_100);
}
// 5
if (getKey(keyPressed) == "Sink Cleaner") {
digitalWrite(WATER, HIGH);
}
// 6
if (getKey(keyPressed) == "Toilet Bowel Cleaner") {
digitalWrite(FLOW, LOW);
}
// 7
if (getKey(keyPressed) == "All Putpose Cleaner") {
analogWrite(Solution_1, flowRate_OFF);
}
// 8
if (getKey(keyPressed) == "Mild Cleaner") {
}
// 9
if (getKey(keyPressed) == "Heavey Duty Cleaner") {
analogWrite(Solution_1, flowRate_OFF);
}
// *
if (getKey(keyPressed) == "Rinse") {
digitalWrite(WATER, HIGH);
analogWrite(Solution_1, flowRate_MAX);
}
// 0
// #
if(getKey(keyPressed) =="ERROR")
{
//Serial.print("ERROR: ");
}
if (getKey(keyPressed) == "Hand Soap LD") {
analogWrite(Solution_1, flowRate_MAX);
}
if (getKey(keyPressed) == "Hand Soap MD") {
analogWrite(Solution_1, flowRate_MAX);
}
if (getKey(keyPressed) == "Hand Soap HD") {
analogWrite(Solution_1, flowRate_MAX);
}
if (getKey(keyPressed) == "Floors") {
analogWrite(Solution_1, flowRate_MAX);
}
if (getKey(keyPressed) == "Degreaser") {
digitalWrite(WATER, HIGH);
}
if (getKey(keyPressed) == "Sanitize") {
digitalWrite(WATER, HIGH);
digitalWrite(FLOW, LOW);
analogWrite(Solution_2, flowRate_OFF);
analogWrite(Solution_3, flowRate_OFF);
analogWrite(Solution_1, flowRate_MAX);
}
} // end loop
// *******************
// * myFunctions *
// *******************
char* getKey(char *k)
{ for(int i=0; i<16; i++) {
if(specialKeysID[i] == k) return specialKeys[i]; }
}
unsigned long displayStartTime(){
KEYPRESS_TIMER_START = millis();
Serial.print( "Initialized keypress time to: ");
Serial.println(KEYPRESS_TIMER_START); Serial.println("sec");
return(KEYPRESS_TIMER_START);
}
int checkforKeyPresstimeOut() {
KEYPRESS_TIMER_NOW = millis();
KEYPRESS_TIMER = KEYPRESS_TIMER_NOW - KEYPRESS_TIMER_START;
if (KEYPRESS_TIMER >= KEYPRESSED_TIME_MAX * 1000){
KEYPRESS_TIMEOUT = true;
return(KEYPRESS_TIMEOUT);
}
}