As described, I want to change the pitch of the buzzed when buttons are pressed on my remote. I have compiled and verified the code before uploading but I don't get any sound out of it. The IR receiver flashes like it should but no sound.
I didn't use the Tone.h library because it uses the same interrupts as IR Remote (or so I'm told). If you have any other suggestions to get around that I'm open to it. The pitchlist.h is just pitches.h with all the frequency numbers for each note with a different name. Didn't want mine to have the same name.
My setup is ground and power to the IR receiver and passive buzzer with pin 7 going to the IR and pin 9 to the buzzer.
I've attached a fritzing of the setup. My buzzer has a ground, power, and signal; couldn't find one like it in fritzing.
Thanks in advance!
#include <IRremote.h>
#include <TonePlayer.h>
#include "pitchlist.h"
const int RECV_PIN = 7;
IRrecv irrecv(RECV_PIN);
decode_results results;
unsigned long key_value = 0;
TonePlayer tone1(TCCR1A, TCCR1B, OCR1AH, OCR1AL, TCNT1H, TCNT1L); //pin 9
int duration = 200;
int notepin = 9;
// notes in the melody:
int melody[] = {
NOTE_C5, NOTE_D5, NOTE_DS5, NOTE_E5, NOTE_F5, NOTE_G5, NOTE_A5, NOTE_AS5, NOTE_B5, NOTE_C6};
void setup(){
Serial.begin(9600);
irrecv.enableIRIn();
irrecv.blink13(true);
}
void loop(){
if (irrecv.decode(&results)){
if (results.value == 0XFFFFFFFF)
results.value = key_value;
switch(results.value){
case 0xB92:
playNote(melody[0], duration);
break;
case 0x80B92:
playNote(melody[1], duration);
break;
case 0x40B92:
playNote(melody[2], duration);
break;
case 0xC0B92:
playNote(melody[3], duration);
break;
case 0x20B92:
playNote(melody[4], duration);
break;
case 0xA0B92:
playNote(melody[5], duration);
break;
case 0x60B92:
playNote(melody[6], duration);
break;
case 0xE0B92:
playNote(melody[7], duration);
break;
case 0x10B92:
playNote(melody[8], duration);
break;
case 0x90B92:
playNote(melody[9], duration);
break;
}
key_value = results.value;
irrecv.resume();
}
}
void playNote(int note, int time) {
tone1.tone(note);
delay(time);
tone1.noTone();
}