I cant seem to find the cause of this error. I've reviewed other posts and I think I've corrected everything that is mentioned... The specific errors are:
> C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino\main.cpp: In function 'main':
> C:\Users\don_d\OneDrive\Documents\Arduino\MJUK\RemoteTestv5\RemoteTestv5.ino:106:12: warning: 'prevposSlide' may be used uninitialized in this function [-Wmaybe-uninitialized]
> else if ( prevposSlide == Right ) { //3g
> ^
> C:\Users\don_d\OneDrive\Documents\Arduino\MJUK\RemoteTestv5\RemoteTestv5.ino:48:7: note: 'prevposSlide' was declared here
> int prevposSlide = Left;
> ^
Note that the quoted declaration initializes the variable in the warning. You can see this in my sketch below. In addition, there are two other variables that I use in a similar way, but so far, I dont get an error with them.
// start
// Remote Control Wiring/Operation Test Sketch v5
// (c) 2022 Don Lutz
#define UpDownPin A0
#define PeekOutPin A1
#define SlideLeftPin A2
#define SlideRightPin A3
#define Forever true
enum Command {Up, Down, PeekOut, Hide, Left, Center, Right };
bool UpDown = true;
bool Peek = true;
bool SlideLeft = true;
bool SlideRight = true;
void setup() {
Serial.begin(9600);
pinMode(UpDownPin, INPUT_PULLUP);
pinMode(PeekOutPin, INPUT_PULLUP);
pinMode(SlideLeftPin, INPUT_PULLUP);
pinMode(SlideRightPin, INPUT_PULLUP);
}
bool checkButtons() {
bool isCommand;
UpDown = ! bool(digitalRead(UpDownPin));
Peek = ! bool(digitalRead(PeekOutPin));
SlideLeft = ! bool(digitalRead(SlideLeftPin));
SlideRight = ! bool(digitalRead(SlideRightPin));
isCommand = UpDown || Peek || SlideLeft || SlideRight;
return isCommand;
}
void loop() {
bool noCommand = true;
int prevposUpDown = Down;
int posUpDown;
int prevposPeek = Hide;
int posPeek;
int prevposSlide = Left;
int posSlide;
const int debounceDelay = 500;
unsigned long now;
unsigned long then;
then = millis();
while (Forever) { //1
noCommand = true;
// GET REMOTE CONTROL COMMAND !!!
while (noCommand) { //2a
now = millis();
if ((now - then) > debounceDelay) { //3a
if (checkButtons()) {//4a
then = millis();
noCommand = false;
}//4a
}//3a
}//2a
// PROCESS BUTTON PRESSED
if (UpDown) {//2b
if (prevposUpDown == Down ) {//3b
Serial.println("[A] Dog pops up !");
posUpDown = Up;
}//3b
else if (prevposUpDown == Up) {//3c
Serial.println("[A] Dog pops down !!");
posUpDown = Down;
}//3c
prevposUpDown = posUpDown;
UpDown = false;
}//2b
if (Peek) {//2d
if ( prevposPeek == Hide ) {//3d
Serial.println("[B] Dog peeks out !!");
posPeek = PeekOut;
}//3d
else if ( prevposPeek == PeekOut ) {//3e
Serial.println("[B] Dog hides !!");
posPeek = Hide;
}//3e
prevposPeek = posPeek;
Peek = false;
}//2d
if (SlideRight) {//2f
if ( prevposSlide == Left ) {//3f
Serial.println("[C] Dog slides to the right !!!");
posSlide = Right;
}//3f
else if ( prevposSlide == Right ) { //3g
Serial.println("[C] Dog is already to the right !!!");
posSlide = Right;
}//3g
prevposSlide = posSlide;
SlideRight = false;
}//2f
if (SlideLeft) {//2h
if ( prevposSlide == Right ) {//3h
Serial.println("[D] Dog slides to the left !!!!");
posSlide = Left;
}//3h
else if ( prevposSlide == Left ) {//3i
Serial.println("[D] Dog is already to the left !!!!");
posSlide = Left;
}//3i
prevposSlide = posSlide;
SlideLeft = false;
}//2h
}//1
}// loop
// end