So I am trying to control an 8 ohm speaker (does have an amplifier) with a cheap little IR remote and receiver. I know all the hex values of the buttons I want using the serial monitor page. I believe that my code should most likely work although I'm sure there's errors somewhere. I get an error in compiling that I'll attach a screenshot of because the error code itself is far too long. I believe it's something about the library im using or its installation. I know that the IRremote.h library (installed directly from arduino libraries) can interfere with the built in library named something like "Robot IR Remote" so i deleted that from the installation location library folders. Github also said to do that (i also tried installing from github in hopes it would change something. I'm at a loss for what to do next and I just want this remote control to work. Any help is much appreciated!
Here is the code:
#include <boarddefs.h>
#include <IRremote.h>
#include <IRremoteInt.h>
#include <ir_Lego_PF_BitStreamEncoder.h>
// Define hex values for IR Remote buttons 1-9
#define Button_1 0xFF30CF
#define Button_2 0xFF18E7
#define Button_3 0xFF7A5
#define Button_4 0xFF10EF
#define Button_5 0xFF38C7
#define Button_6 0xFF5AA5
#define Button_7 0xFF42BD
#define Button_8 0xFF4AB5
#define Button_9 0xFF52AD
// Define tone Hz values for different buttons
#define NOTE_C4 262
#define NOTE_CS4 277
#define NOTE_D4 294
#define NOTE_DS4 311
#define NOTE_E4 330
#define NOTE_F4 349
#define NOTE_FS4 370
#define NOTE_G4 392
#define NOTE_GS4 415
#define NOTE_A5 440
#define NOTE_AS5 466
#define NOTE_B5 494
#define NOTE_C5 523
#define NOTE_CS5 554
#define NOTE_D5 587
int receiver = 13; // initialize pin 11 as our IR Receiver pin
int speaker = 11; // initialize pin 11 as speaker;
uint32_t Previous; // default/previous value for IR recv if it shows 0xFFFFFFFF
// NOTE: 0xFFFFFFFF appears after the button's HEX value if it's continuously held
IRrecv irrecv(receiver); // creates new instance of receiver
decode_results results;
void setup() {
Serial.begin(9600); // begin serial data
irrecv.enableIRIn(); // start the receiver
}
void loop() {
if (irrecv.decode(&results)) { // if we receive an IR signal
if (results.value==0xFFFFFFFF) { // if button is still being held down
results.value = Previous; // default to the initial HEX value of button being held down
}
switch(results.value) {
case Button_1: tone(speaker, NOTE_C4, 500); break;
case Button_2: tone(speaker, NOTE_D4, 500); break;
case Button_3: tone(speaker, NOTE_E4, 500); break;
case Button_4: tone(speaker, NOTE_F4, 500); break;
case Button_5: tone(speaker, NOTE_G4, 500); break;
case Button_6: tone(speaker, NOTE_A5, 500); break;
case Button_7: tone(speaker, NOTE_B5, 500); break;
case Button_8: tone(speaker, NOTE_C5, 500); break;
case Button_9: tone(speaker, NOTE_D5, 500); break;
}
Serial.println(results.value, HEX); // display hex results
irrecv.resume(); // next value
}
Previous=results.value;
}
