Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <IRremote.h>
- int RECV_PIN = 3;
- int BLUE_LED = 13;
- int RED_LED = 12;
- IRrecv irrecv(RECV_PIN);
- decode_results results;
- void setup() {
- // initialize the digital pin as an output.
- pinMode(RECV_PIN, INPUT);
- pinMode(BLUE_LED, OUTPUT);
- pinMode(RED_LED, OUTPUT);
- irrecv.enableIRIn(); // Start the receiver
- Serial.begin(9600);
- }
- void loop() {
- int i=0;
- if (irrecv.decode(&results))
- {
- translateIR();
- irrecv.resume(); // Receive the next value
- }
- }
- void translateIR() // takes action based on IR code received describing Car MP3 IR codes
- {
- switch(results.value){
- case 0xFFA25D:
- Serial.println(" CH- ");
- break;
- case 0xFF629D:
- Serial.println(" CH ");
- break;
- case 0xFFE21D:
- Serial.println(" CH+ ");
- break;
- case 0xFF22DD:
- Serial.println(" blue LED off ");
- digitalWrite(13,LOW);
- break;
- case 0xFF02FD:
- Serial.println(" blue LED on ");
- digitalWrite(13, HIGH);
- break;
- case 0xFFC23D:
- Serial.println(" PLAY/PAUSE ");
- break;
- case 0xFFE01F:
- Serial.println(" VOL- ");
- break;
- case 0xFFA857:
- Serial.println(" VOL+ ");
- break;
- case 0xFF906F:
- Serial.println(" EQ ");
- break;
- case 0xFF6897:
- Serial.println(" 0 ");
- break;
- case 0xFF9867:
- Serial.println(" 100+ ");
- break;
- case 0xFFB04F:
- Serial.println(" 200+ ");
- break;
- case 0xFF30CF:
- Serial.println(" 1 ");
- break;
- case 0xFF18E7:
- Serial.println(" 2 ");
- break;
- case 0xFF7A85:
- Serial.println(" 3 ");
- break;
- case 0xFF10EF:
- Serial.println(" 4 ");
- break;
- case 0xFF38C7:
- Serial.println(" 5 ");
- break;
- case 0xFF5AA5:
- Serial.println(" 6 ");
- break;
- case 0xFF42BD:
- Serial.println(" 7 ");
- break;
- case 0xFF4AB5:
- Serial.println(" 8 ");
- break;
- case 0xFF52AD:
- Serial.println(" 9 ");
- break;
- default:
- Serial.print(" unknown button ");
- Serial.println(results.value, HEX);
- }
- delay(100);
- }
- long Piezo1 = 0xFF40BF;
- long Piezo2 = 0xFF906F;
- long Piezo3 = 0xFFD02F;
- long Piezo4 = 0xFF10EF;
- if (results.value == RED_LED_OFF)
- Serial.println ("Piezo1");
- digitalWrite
- #include <LiquidCrystal.h>
- LiquidCrystal lcd(4,6,10,11,12,13);
- int Piezo = 5;
- int length = 38;
- char notes[] = "gfedcdecdefdedcBcc gfedcdecdefdedcBcc";
- int beats[] = {3,1,2,2,2,2,2,2,1,1,1,1,3,1,2,2,2,2,4,3,1,2,2,2,2,2,2,1,1,1,1,3,1,2,2,2,2,4};
- int tempo = 200;
- void playTone(int tone, int duration) {
- for (long i = 0; i < duration * 1000L; i += tone * 2) {
- digitalWrite(Piezo, HIGH);
- delayMicroseconds(tone);
- digitalWrite(Piezo, LOW);
- delayMicroseconds(tone);
- }
- }
- void playNote(char note, int duration) {
- char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C','B'};
- int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956, 27.5};
- char names_sharp[] = { 'c', 'd', 'f', 'g', 'a', 'C', 'D', 'F', 'G', 'A' };
- int tones_sharp[] = { 1804, 1607, 1351, 1204, 1073, 902, 804, 676, 602, 536 };
- // play the tone corresponding to the note name
- for (int i = 0; i < 8; i++) {
- if (names[i] == note) {
- playTone(tones[i], duration);
- }
- }
- }
- void setup() {
- pinMode(Piezo, OUTPUT);
- lcd.begin (16,2);
- lcd.setCursor (0,0);
- lcd.print ("MERRY CHRISTMAS &");
- // set the cursor to column o, line 1
- //line 1 is the second row, since counting begins with 0
- lcd.setCursor (1,1) ;
- //print to the second line
- lcd.print ("HAPPY HOLIDAYS!");
- }
- void loop() {
- for (int i = 0; i < length; i++) {
- if (notes[i] == ' ') {
- delay(beats[i] * tempo); // rest
- } else {
- playNote(notes[i], beats[i] * tempo);
- }
- // pause between notes
- delay(tempo / 310);
- }
- }
- }
- else if (results.value == Piezo2 )
- {
- Serial.println ("Red led on");
- digitalWrite;
- #include <LiquidCrystal.h>
- LiquidCrystal lcd(4,6,10,11,12,13);
- int Piezo = 5;
- int length = 32;
- char notes[] = "gefgg gabCC efggagff egcedffccc gefgg gabCC efggagff egcedffcce";
- int beats[] = {2,1,1,2,3,.5,1,1,1,2,3.5,1,1,1,2,2,1,1,1,4,2,2,2,2,1,2,2,4,2.5,.5,1,1,2,3,.5,1,1,1,2,3.5,1,1,1,2,2,1,1,1,4,2,2,2,2,2,3,2.5,4};
- int tempo = 250;
- void playTone(int tone, int duration) {
- for (long i = 0; i < duration * 1000L; i += tone * 2) {
- digitalWrite(Piezo, HIGH);
- delayMicroseconds(tone);
- digitalWrite(Piezo, LOW);
- delayMicroseconds(tone);
- }
- }
- void playNote(char note, int duration) {
- char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C','B'};
- int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956, 27.5};
- // play the tone corresponding to the note name
- for (int i = 0; i < 8; i++) {
- if (names[i] == note) {
- playTone(tones[i], duration);
- }
- }
- }
- void setup() {
- pinMode(Piezo, OUTPUT);
- lcd.begin (16,2);
- lcd.setCursor (0,0);
- lcd.print ("MERRY CHRISTMAS &");
- // set the cursor to column o, line 1
- //line 1 is the second row, since counting begins with 0
- lcd.setCursor (1,1) ;
- //print to the second line
- lcd.print ("HAPPY HOLIDAYS!");
- }
- void loop() {
- for (int i = 0; i < length; i++) {
- if (notes[i] == ' ')
- {
- delay(beats[i] * tempo); // rest
- } else {
- playNote(notes[i], beats[i] * tempo);
- }
- // pause between notes
- delay(tempo / 310);
- }
- }
- }
- else if (results.value == Piezo3 )
- {
- digitalWrite
- #include <LiquidCrystal.h>
- LiquidCrystal lcd(4,6,10,11,12,13);
- int Piezo = 5;
- int length = 31;
- char notes[] = "dggagfeeeaabagfddbbCbageddeafg";
- int beats[] = {2,2,1,1,1,1,2,2,2,2,1,1,1,1,2,2,2,2,1,1,1,1,2,2,1,1,2,2,2,4};
- int tempo = 190;
- void playTone(int tone, int duration) {
- for (long i = 0; i < duration * 1000L; i += tone * 2) {
- digitalWrite(Piezo, HIGH);
- delayMicroseconds(tone);
- digitalWrite(Piezo, LOW);
- delayMicroseconds(tone);
- }
- }
- void playNote(char note, int duration) {
- char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C', 'D', 'E', 'F', 'G', 'A', 'B' };
- int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956, 851, 758, 716, 636, 568, 506 };
- // these are the "sharp" versions of each note e.g. the first value is for "c#"
- char names_sharp[] = { 'c', 'd', 'f', 'g', 'a', 'C', 'D', 'F', 'G', 'A' };
- int tones_sharp[] = { 1804, 1607, 1351, 1204, 1073, 902, 804, 676, 602, 536 };
- // play the tone corresponding to the note name
- for (int i = 0; i < 8; i++) {
- if (names[i] == note) {
- playTone(tones[i], duration);
- }
- }
- }
- void setup() {
- pinMode(Piezo, OUTPUT);
- lcd.begin (16,2);
- lcd.setCursor (0,0);
- lcd.print ("MERRY CHRISTMAS &");
- // set the cursor to column o, line 1
- //line 1 is the second row, since counting begins with 0
- lcd.setCursor (1,1) ;
- //print to the second line
- lcd.print ("HAPPY HOLIDAYS!");
- }
- void loop() {
- for (int i = 0; i < length; i++) {
- if (notes[i] == ' ') {
- delay(beats[i] * tempo); // rest
- } else {
- playNote(notes[i], beats[i] * tempo);
- }
- // pause between notes
- delay(tempo / 15);
- }
- }
- else if (results.value == Piezo4 )
- {
- Serial.println ("Red led on");
- digitalWrite;
- #include <LiquidCrystal.h>
- LiquidCrystal lcd(4,6,10,11,12,13);
- int Piezo = 5;
- int length = 26;
- char notes[] = "eeeeeeegcde fffffeeeeddedg";
- int beats[] = { 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2};
- int tempo = 300;
- void playTone(int tone, int duration) {
- for (long i = 0; i < duration * 1000L; i += tone * 2) {
- digitalWrite(Piezo, HIGH);
- delayMicroseconds(tone);
- digitalWrite(Piezo, LOW);
- delayMicroseconds(tone);
- }
- }
- void playNote(char note, int duration) {
- char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
- int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };
- // play the tone corresponding to the note name
- for (int i = 0; i < 8; i++) {
- if (names[i] == note) {
- playTone(tones[i], duration);
- }
- }
- }
- void setup() {
- pinMode(Piezo, OUTPUT);
- lcd.begin (16,2);
- lcd.setCursor (0,0);
- lcd.print ("MERRY CHRISTMAS &");
- // set the cursor to column o, line 1
- //line 1 is the second row, since counting begins with 0
- lcd.setCursor (1,1) ;
- //print to the second line
- lcd.print ("HAPPY HOLIDAYS!");
- }
- void loop() {
- for (int i = 0; i < length; i++) {
- if (notes[i] == ' ') {
- delay(beats[i] * tempo); // rest
- } else {
- playNote(notes[i], beats[i] * tempo);
- }
- // pause between notes
- delay(tempo / 2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement