Hello Arduino Forums,
Context:
I am using an Arduino Uno, a 2x16 LCD Screen, and an IR Remote. What I want to accomplish with it is that I want to make it so that I can use VOL+/- buttons and CH+/- buttons to change the value for the hours and minutes, then display them onto the LCD Screen's bottom line. When the user inputs their desired time, they would press the EQ button to finalize their decision, and exit the switch statement.
Essentially, I'm trying to make it so a user can input a time (whilst seeing the numbers change on the screen as well), and press EQ to finalize.
Problem:
Right now, I'm trying to use a switch statement to accomplish this task. I made it so each case is the (decoded) number code for the remote buttons that need to be pressed in order to fulfill this function. However, when I run this code in TinkerCad, it displays an error that says there is a duplicate case value(case -32641 with all the others).
When I delete case -32641, it runs, but the Serial Monitor only outputs readResults as -32641 whenever I press any button. Does anyone have any advice on how to fix this so it can work properly?
Here is my code:
//LCD code
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
int hrs = 0;
int mins = 0;
//Remote Code
#include <IRremote.h> //including infrared remote header file
int RECV_PIN = 8; // the pin where you connect the output pin of IR sensor
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup() {
hrs = 0;
mins = 0;
//LCD Code
lcd.begin(16,2);
Serial.begin(9600);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Time: 17:20");
lcd.setCursor(0,1);
lcd.print("Input alarm time");
delay(1000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Time: 17:20");
lcd.setCursor(0,1);
lcd.print("CH+/CH- for mins");
delay(1000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Time: 17:20");
lcd.setCursor(0,1);
lcd.print("+/- for hrs");
delay(1000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Time: 17:20");
//IR Remote
irrecv.enableIRIn();
}
void loop() {
int readResults = results.value;// Results of decoding are stored in result.value
//Remote input code
if (irrecv.decode(&results)){// Returns 0 if no data ready, 1 if data ready.
int readResults = results.value;// Results of decoding are stored in result.value
Serial.println(readResults);
switch(readResults){
case 16613503 :
{
//VOL+
hrs +=1;
//Makes sure user doesn't input invalid hours
if(hrs > 23){
hrs = 0;
}
Serial.println(hrs + ":" + mins);
}
case 16617583 :
{
//VOL-
hrs -=1;
//Makes sure user doesn't input invalid hours
if(hrs < 0){
hrs = 23;
}
}
case 16601263 :
{
//CH+
mins +=1;
//Makes sure user doesn't input invalid minutes
if(mins > 59){
mins = 0;
}
}
case 16584943 :
{
//CH-
mins -=1;
//Makes sure user doesn't input invalid minutes
if(mins < 0){
mins = 59;
}
}
case 16625743 :
{
//EQ
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Time: 17:20");
lcd.setCursor(0,1);
lcd.print("Input Valid");
break;
}
case -32641 :
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Time: 17:20");
lcd.setCursor(0,1);
lcd.print(hrs + ":" + mins);
}
}//End of Switch Statement
}//End of If statement
}