Hello
This is my first post - please bear with me.
I'm trying to compile a code for an ESP32 DEVKIT V1 and it keeps giving me the error "invalid conversion from 'const unsigned int*' to 'int*' [-fpermissive]". The code compiles and runs fine on arduino uno and nano (although a version with software serial instead of hardware serial), but when I try to compile it for an ESP32 or ESP8266 board the error is returned. Can anybody explain to me what the problem is and maybe point me toward a solution?
I would be grateful - thx.
The code is supposed to capture IR signals, compares it and sends serial commands to a media player device if there is a match.
This is the code:
#define DEBUG
#include <IRremote.h>
const unsigned int signal1[23] PROGMEM = {850,1700,850,850,850,850,850,850,850,850,850,850,850,850,850,850,850,1700,1700,850,850,1700,850};
const unsigned int signal2[23] PROGMEM = {850,850,850,850,1700,850,850,850,850,850,850,850,850,850,850,850,850,1700,1700,850,850,850,850};
const unsigned int signal3[23] PROGMEM = {850,1700,1700,850,850,850,850,850,850,850,850,850,850,850,850,850,850,1700,1700,850,850,1700,850};
const unsigned int signal4[23] PROGMEM = {850,850,1700,1700,850,850,850,850,850,850,850,850,850,850,850,850,850,1700,1700,850,850,1700,850};
const int* signalArray[] = {signal1, signal2, signal3, signal4};
// Calculate the number of elements in the array (there's an assumption here that all patterns are of the same length
const int numSignals = sizeof(signalArray) / sizeof(signalArray[0]);
// Define the correct sequence of buttons that player need to enter
const int correctSequence1 = 0;
const int correctSequence2 = 1;
const int correctSequence3 = 2;
const int correctSequence4 = 3;
const int sequenceLength = 1;
char message;
unsigned long startMillis; //some global variables available anywhere in the program
unsigned long currentMillis;
const unsigned long period = 12000; //the value is a number of milliseconds
//Serial to media player
#define RXD2 16
#define TXD2 17
IRrecv irrecv(5);
// Define object to store IR signal received
decode_results results;
// Keep track of how far through the sequence we are
int sequenceProgress = 0;
void setup() {
Serial2.begin(9600);
Serial.begin(115200);
// Start the IR receiver
Serial.print(F("Initialising IR receiver..."));
irrecv.enableIRIn();
Serial.println(F("done"));
// Print the pattern we're listening for
#ifdef DEBUG
Serial.print(F("Listening for pattern "));
for(int i=0; i<sequenceLength; i++){
Serial.print(correctSequence1);
Serial.print(correctSequence2);
Serial.print(correctSequence3);
Serial.print(correctSequence4);
Serial.print(" ");
}
Serial.println("");
#endif
}
void sendPatternToSerialMonitor (decode_results *results) {
// Variable declaration
Serial.print(F("unsigned int receivedData["));
// Array size
Serial.print(results->rawlen - 1, DEC);
// Begin array
Serial.print("] = {");
// Dump data
for(int i=1; i<results->rawlen; i++) {
long val = results->rawbuf[i] * USECPERTICK;
Serial.print(val, DEC);
if(i<results->rawlen-1) { Serial.print(","); }
}
// End printout
Serial.println("};");
}
// Compare the pattern decoded from the IR sensor to a supplied pattern
bool compareCode(decode_results *results, int code[], int tolerance){
// Compare each time interval in the results (ignoring the first) to the supplied code
for(int i=1; i<results->rawlen; i++) {
long val = results->rawbuf[i] * USECPERTICK;
int expected = pgm_read_word(&code[i-1]);
if(abs(val - expected) > tolerance) {
return false;
}
}
return true;
}
void loop() {
currentMillis = millis();
if (currentMillis - startMillis >= period)
{
// If a valid IR pattern can be decoded
if(irrecv.decode(&results)) {
#ifdef DEBUG
// Dump the pattern received to the serial monitor
sendPatternToSerialMonitor(&results);
#endif
// Loop over each known button and compare to input pattern
for(int i=0;i<numSignals;i++){
if(compareCode(&results, signalArray[i], 200)) {
Serial.print("Pattern matched: ");
Serial.println(i);
// Was this the correct next input in the pattern?
if(i==correctSequence1) {
#ifdef DEBUG
#endif
sequenceProgress++;
if(sequenceProgress==sequenceLength) {
Serial2.write(0x01);
Serial.println(F("---------------"));
Serial.println("MEDIE1");
Serial.println(F("---------------"));
sequenceProgress=0;
startMillis = millis();
}
}
if(i==correctSequence2) {
#ifdef DEBUG
#endif
sequenceProgress++;
if(sequenceProgress==sequenceLength) {
Serial2.write(0x02);
Serial.println(F("---------------"));
Serial.println("MEDIE2");
Serial.println(F("---------------"));
sequenceProgress=0;
startMillis = millis();
}
}
if(i==correctSequence3) {
#ifdef DEBUG
#endif
sequenceProgress++;
if(sequenceProgress==sequenceLength) {
Serial2.write(0x03);
Serial.println(F("---------------"));
Serial.println("MEDIE3");
Serial.println(F("---------------"));
sequenceProgress=0;
startMillis = millis();
}
}
if(i==correctSequence4) {
#ifdef DEBUG
#endif
sequenceProgress++;
if(sequenceProgress==sequenceLength) {
Serial2.write(0x04);
Serial.println(F("---------------"));
Serial.println("MEDIE4");
Serial.println(F("---------------"));
sequenceProgress=0;
startMillis = millis();
}
}
else {
#ifdef DEBUG
Serial.println("Incorrect input! Back to the beginning..");
#endif
sequenceProgress=0;
}
// Match was found, so no need to check other patterns
break;
}
}
//To prevent repeat button presses, pause before interpreting next signal
delay(500);
// Receive the next value
irrecv.resume();
}
}
}
And this is the compilation error message:
In file included from C:\Users\jakob\Documents\Arduino\Kladder\SpriteSLET\SpriteSLET.ino:2:0:
C:\Users\jakob\Documents\Arduino\libraries\IRremote/IRremote.h:365:23: error: 'SEND_PIN' was not declared in this scope
const int sendPin = SEND_PIN;
^
SpriteSLET:10:63: error: invalid conversion from 'const unsigned int*' to 'const int*' [-fpermissive]
const int* signalArray[] = {signal1, signal2, signal3, signal4};
^
SpriteSLET:10:63: error: invalid conversion from 'const unsigned int*' to 'const int*' [-fpermissive]
SpriteSLET:10:63: error: invalid conversion from 'const unsigned int*' to 'const int*' [-fpermissive]
SpriteSLET:10:63: error: invalid conversion from 'const unsigned int*' to 'const int*' [-fpermissive]
C:\Users\jakob\Documents\Arduino\Kladder\SpriteSLET\SpriteSLET.ino: In function 'void loop()':
SpriteSLET:107:45: error: invalid conversion from 'const int*' to 'int*' [-fpermissive]
if(compareCode(&results, signalArray*, 200)) {*
- ^*
C:\Users\jakob\Documents\Arduino\Kladder\SpriteSLET\SpriteSLET.ino:78:6: note: initializing argument 2 of 'bool compareCode(decode_results*, int*, int)'
bool compareCode(decode_results *results, int code[], int tolerance){ - ^*
exit status 1
invalid conversion from 'const unsigned int*' to 'const int*' [-fpermissive]