Program worked fine on an Arduino Uno, but ends up in an boot loop on ESP32. Could need some help understanding the line of code causing the error. The program is as follows, with the error: Guru
Meditation Error: Core 1 panic'ed (LoadProhibited) Exception was unhandled
const int dimensionY = 26;
const int dimensionX = 25;
int midX;
int midY;
int x = 0;
int y = 0;
int xVal, yVal, mainMotor, rightMotor, leftMotor;
float diffDeg;
float diffValue;
float diffMotor;
void setup() {
Serial.begin(115200);
pinMode(dimensionY, INPUT);
pinMode(dimensionX, INPUT);
analogReadResolution(10);
}
void loop() {
//middle value for joystick
midX = analogRead(dimensionX);
midY = analogRead(dimensionY);
x = analogRead(dimensionX);
y = analogRead(dimensionY);
joyStick();
}
int joyStick() {
xVal = map(x, midX, 1023, 0, 400);
yVal = map(y, midY, 0, 0, 400);
diffDeg = atan2(yVal, xVal)*180/3.1415;
if (diffDeg < 0) {
diffDeg += 360;
}
if (diffDeg < 90) {
diffValue = map(diffDeg, 0, 90, 0, 100);
if (diffDeg < 45) {
mainMotor = xVal;
} else {
mainMotor = yVal;
}
} else if (diffDeg < 190) {
diffValue = map(diffDeg, 90, 180, 100, 0);
if (diffDeg < 135) {
mainMotor = abs(yVal);
} else {
mainMotor = abs(xVal);
}
} else if (diffDeg < 270) {
diffValue = map(diffDeg, 180, 270, 0, 100);
if (diffDeg < 225) {
mainMotor = xVal;
} else {
mainMotor = yVal;
}
} else {
diffValue = map(diffDeg, 270, 360, 100, 0);
if (diffDeg < 315) {
mainMotor = yVal;
} else {
mainMotor = -xVal;
}
}
mainMotor = constrain(mainMotor, -400, 400);
if (abs(mainMotor) < 15) {
mainMotor = 0;
}
diffMotor = mainMotor*diffValue/100;
if (diffDeg > 90 && diffDeg < 270) {
rightMotor = diffMotor;
leftMotor = mainMotor;
} else {
rightMotor = mainMotor;
leftMotor = diffMotor;
}
// Serial.print(rightMotor);
// Serial.print(",");
// Serial.println(leftMotor);
}
Error in Serial:
rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1324
ho 0 tail 12 room 4
load:0x40078000,len:13508
load:0x40080400,len:3604
entry 0x400805f0
Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC : 0x400d12d8 PS : 0x00060d30 A0 : 0x800d1370 A1 : 0x3ffb27d0
A2 : 0x00000007 A3 : 0x3ffc114c A4 : 0x3ffc1150 A5 : 0x00000015
A6 : 0x43870000 A7 : 0x00000001 A8 : 0x800d12a6 A9 : 0x3ffb27c0
A10 : 0x40e47ae1 A11 : 0x42c80000 A12 : 0x0000005a A13 : 0x00000064
A14 : 0xffffffbe A15 : 0x00000000 SAR : 0x0000001d EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000015 LBEG : 0x400029ac LEND : 0x400029cb LCOUNT : 0x00000000
Backtrace:0x400d12d5:0x3ffb27d00x400d136d:0x3ffb2800 0x400d1e99:0x3ffb2820
ELF file SHA256: 0000000000000000
Rebooting...
ets Jun 8 2016 00:22:57