Advertisement
esha492

FINAL REMOTE+LCD CODE

Nov 9th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.99 KB | None | 0 0
  1.  
  2.  
  3.  
  4. #include <IRremote.h>
  5. int RECV_PIN = 3;
  6. int BLUE_LED = 13;
  7. int RED_LED = 12;
  8.  
  9.  
  10.  
  11. IRrecv irrecv(RECV_PIN);
  12. decode_results results;
  13.  
  14. void setup() {
  15. // initialize the digital pin as an output.
  16. pinMode(RECV_PIN, INPUT);
  17. pinMode(BLUE_LED, OUTPUT);
  18. pinMode(RED_LED, OUTPUT);
  19. irrecv.enableIRIn(); // Start the receiver
  20. Serial.begin(9600);
  21. }
  22. void loop() {
  23. int i=0;
  24. if (irrecv.decode(&results))
  25. {
  26.  
  27. translateIR();
  28.  
  29.  
  30. irrecv.resume(); // Receive the next value
  31.  
  32. }
  33. }
  34.  
  35. void translateIR() // takes action based on IR code received describing Car MP3 IR codes
  36. {
  37. switch(results.value){
  38. case 0xFFA25D:
  39. Serial.println(" CH- ");
  40. break;
  41. case 0xFF629D:
  42. Serial.println(" CH ");
  43. break;
  44. case 0xFFE21D:
  45. Serial.println(" CH+ ");
  46. break;
  47. case 0xFF22DD:
  48. Serial.println(" blue LED off ");
  49. digitalWrite(13,LOW);
  50. break;
  51. case 0xFF02FD:
  52. Serial.println(" blue LED on ");
  53. digitalWrite(13, HIGH);
  54. break;
  55. case 0xFFC23D:
  56. Serial.println(" PLAY/PAUSE ");
  57. break;
  58. case 0xFFE01F:
  59. Serial.println(" VOL- ");
  60. break;
  61. case 0xFFA857:
  62. Serial.println(" VOL+ ");
  63. break;
  64. case 0xFF906F:
  65. Serial.println(" EQ ");
  66. break;
  67. case 0xFF6897:
  68. Serial.println(" 0 ");
  69. break;
  70. case 0xFF9867:
  71. Serial.println(" 100+ ");
  72. break;
  73. case 0xFFB04F:
  74. Serial.println(" 200+ ");
  75. break;
  76. case 0xFF30CF:
  77. Serial.println(" 1 ");
  78. break;
  79.  
  80. case 0xFF18E7:
  81. Serial.println(" 2 ");
  82. break;
  83.  
  84. case 0xFF7A85:
  85. Serial.println(" 3 ");
  86. break;
  87.  
  88. case 0xFF10EF:
  89. Serial.println(" 4 ");
  90. break;
  91.  
  92. case 0xFF38C7:
  93. Serial.println(" 5 ");
  94. break;
  95.  
  96. case 0xFF5AA5:
  97. Serial.println(" 6 ");
  98. break;
  99.  
  100. case 0xFF42BD:
  101. Serial.println(" 7 ");
  102. break;
  103.  
  104. case 0xFF4AB5:
  105. Serial.println(" 8 ");
  106. break;
  107.  
  108. case 0xFF52AD:
  109. Serial.println(" 9 ");
  110. break;
  111.  
  112. default:
  113. Serial.print(" unknown button ");
  114. Serial.println(results.value, HEX);
  115.  
  116. }
  117.  
  118. delay(100);
  119.  
  120.  
  121. }
  122.  
  123. long Piezo1 = 0xFF40BF;
  124. long Piezo2 = 0xFF906F;
  125. long Piezo3 = 0xFFD02F;
  126. long Piezo4 = 0xFF10EF;
  127.  
  128. if (results.value == RED_LED_OFF)
  129.  
  130. Serial.println ("Piezo1");
  131. digitalWrite
  132.  
  133. #include <LiquidCrystal.h>
  134. LiquidCrystal lcd(4,6,10,11,12,13);
  135. int Piezo = 5;
  136. int length = 38;
  137. char notes[] = "gfedcdecdefdedcBcc gfedcdecdefdedcBcc";
  138. 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};
  139.  
  140. int tempo = 200;
  141. void playTone(int tone, int duration) {
  142. for (long i = 0; i < duration * 1000L; i += tone * 2) {
  143. digitalWrite(Piezo, HIGH);
  144. delayMicroseconds(tone);
  145. digitalWrite(Piezo, LOW);
  146. delayMicroseconds(tone);
  147. }
  148. }
  149. void playNote(char note, int duration) {
  150. char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C','B'};
  151. int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956, 27.5};
  152.  
  153. char names_sharp[] = { 'c', 'd', 'f', 'g', 'a', 'C', 'D', 'F', 'G', 'A' };
  154. int tones_sharp[] = { 1804, 1607, 1351, 1204, 1073, 902, 804, 676, 602, 536 };
  155.  
  156. // play the tone corresponding to the note name
  157. for (int i = 0; i < 8; i++) {
  158. if (names[i] == note) {
  159. playTone(tones[i], duration);
  160. }
  161. }
  162. }
  163. void setup() {
  164. pinMode(Piezo, OUTPUT);
  165. lcd.begin (16,2);
  166. lcd.setCursor (0,0);
  167. lcd.print ("MERRY CHRISTMAS &");
  168. // set the cursor to column o, line 1
  169. //line 1 is the second row, since counting begins with 0
  170. lcd.setCursor (1,1) ;
  171. //print to the second line
  172. lcd.print ("HAPPY HOLIDAYS!");
  173. }
  174. void loop() {
  175. for (int i = 0; i < length; i++) {
  176. if (notes[i] == ' ') {
  177. delay(beats[i] * tempo); // rest
  178. } else {
  179. playNote(notes[i], beats[i] * tempo);
  180. }
  181.  
  182. // pause between notes
  183. delay(tempo / 310);
  184. }
  185. }
  186. }
  187. else if (results.value == Piezo2 )
  188. {
  189. Serial.println ("Red led on");
  190. digitalWrite;
  191. #include <LiquidCrystal.h>
  192. LiquidCrystal lcd(4,6,10,11,12,13);
  193.  
  194. int Piezo = 5;
  195. int length = 32;
  196. char notes[] = "gefgg gabCC efggagff egcedffccc gefgg gabCC efggagff egcedffcce";
  197. 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};
  198.  
  199. int tempo = 250;
  200. void playTone(int tone, int duration) {
  201. for (long i = 0; i < duration * 1000L; i += tone * 2) {
  202. digitalWrite(Piezo, HIGH);
  203. delayMicroseconds(tone);
  204. digitalWrite(Piezo, LOW);
  205. delayMicroseconds(tone);
  206. }
  207. }
  208. void playNote(char note, int duration) {
  209. char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C','B'};
  210. int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956, 27.5};
  211.  
  212. // play the tone corresponding to the note name
  213. for (int i = 0; i < 8; i++) {
  214. if (names[i] == note) {
  215. playTone(tones[i], duration);
  216. }
  217. }
  218.  
  219. }
  220. void setup() {
  221. pinMode(Piezo, OUTPUT);
  222. lcd.begin (16,2);
  223. lcd.setCursor (0,0);
  224. lcd.print ("MERRY CHRISTMAS &");
  225. // set the cursor to column o, line 1
  226. //line 1 is the second row, since counting begins with 0
  227. lcd.setCursor (1,1) ;
  228. //print to the second line
  229. lcd.print ("HAPPY HOLIDAYS!");
  230. }
  231. void loop() {
  232. for (int i = 0; i < length; i++) {
  233. if (notes[i] == ' ')
  234. {
  235. delay(beats[i] * tempo); // rest
  236. } else {
  237. playNote(notes[i], beats[i] * tempo);
  238. }
  239.  
  240. // pause between notes
  241. delay(tempo / 310);
  242. }
  243.  
  244. }
  245. }
  246. else if (results.value == Piezo3 )
  247. {
  248. digitalWrite
  249. #include <LiquidCrystal.h>
  250. LiquidCrystal lcd(4,6,10,11,12,13);
  251. int Piezo = 5;
  252. int length = 31;
  253. char notes[] = "dggagfeeeaabagfddbbCbageddeafg";
  254. 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};
  255.  
  256. int tempo = 190;
  257. void playTone(int tone, int duration) {
  258. for (long i = 0; i < duration * 1000L; i += tone * 2) {
  259. digitalWrite(Piezo, HIGH);
  260. delayMicroseconds(tone);
  261. digitalWrite(Piezo, LOW);
  262. delayMicroseconds(tone);
  263. }
  264. }
  265. void playNote(char note, int duration) {
  266. char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C', 'D', 'E', 'F', 'G', 'A', 'B' };
  267. int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956, 851, 758, 716, 636, 568, 506 };
  268.  
  269. // these are the "sharp" versions of each note e.g. the first value is for "c#"
  270. char names_sharp[] = { 'c', 'd', 'f', 'g', 'a', 'C', 'D', 'F', 'G', 'A' };
  271. int tones_sharp[] = { 1804, 1607, 1351, 1204, 1073, 902, 804, 676, 602, 536 };
  272.  
  273. // play the tone corresponding to the note name
  274. for (int i = 0; i < 8; i++) {
  275. if (names[i] == note) {
  276. playTone(tones[i], duration);
  277. }
  278. }
  279. }
  280. void setup() {
  281. pinMode(Piezo, OUTPUT);
  282. lcd.begin (16,2);
  283. lcd.setCursor (0,0);
  284. lcd.print ("MERRY CHRISTMAS &");
  285. // set the cursor to column o, line 1
  286. //line 1 is the second row, since counting begins with 0
  287. lcd.setCursor (1,1) ;
  288. //print to the second line
  289. lcd.print ("HAPPY HOLIDAYS!");
  290. }
  291. void loop() {
  292. for (int i = 0; i < length; i++) {
  293. if (notes[i] == ' ') {
  294. delay(beats[i] * tempo); // rest
  295. } else {
  296. playNote(notes[i], beats[i] * tempo);
  297. }
  298.  
  299. // pause between notes
  300. delay(tempo / 15);
  301. }
  302. }
  303. else if (results.value == Piezo4 )
  304. {
  305. Serial.println ("Red led on");
  306. digitalWrite;
  307.  
  308. #include <LiquidCrystal.h>
  309. LiquidCrystal lcd(4,6,10,11,12,13);
  310. int Piezo = 5;
  311. int length = 26;
  312. char notes[] = "eeeeeeegcde fffffeeeeddedg";
  313. 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};
  314. int tempo = 300;
  315. void playTone(int tone, int duration) {
  316. for (long i = 0; i < duration * 1000L; i += tone * 2) {
  317. digitalWrite(Piezo, HIGH);
  318. delayMicroseconds(tone);
  319. digitalWrite(Piezo, LOW);
  320. delayMicroseconds(tone);
  321. }
  322. }
  323. void playNote(char note, int duration) {
  324. char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
  325. int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };
  326.  
  327. // play the tone corresponding to the note name
  328. for (int i = 0; i < 8; i++) {
  329. if (names[i] == note) {
  330. playTone(tones[i], duration);
  331. }
  332. }
  333. }
  334. void setup() {
  335. pinMode(Piezo, OUTPUT);
  336. lcd.begin (16,2);
  337. lcd.setCursor (0,0);
  338. lcd.print ("MERRY CHRISTMAS &");
  339. // set the cursor to column o, line 1
  340. //line 1 is the second row, since counting begins with 0
  341. lcd.setCursor (1,1) ;
  342. //print to the second line
  343. lcd.print ("HAPPY HOLIDAYS!");
  344. }
  345. void loop() {
  346. for (int i = 0; i < length; i++) {
  347. if (notes[i] == ' ') {
  348. delay(beats[i] * tempo); // rest
  349. } else {
  350. playNote(notes[i], beats[i] * tempo);
  351. }
  352.  
  353. // pause between notes
  354. delay(tempo / 2);
  355.  
  356. }
  357. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement