esha492

SANTA CLAUS FINAL

Nov 7th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2. LiquidCrystal lcd(4,6,10,11,12,13);
  3.  
  4. int Piezo = 5;
  5. int length = 32;
  6. char notes[] = "gefgg gabCC efggagff egcedffccc gefgg gabCC efggagff egcedffcce";
  7. 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};
  8.  
  9. int tempo = 250;
  10. void playTone(int tone, int duration) {
  11. for (long i = 0; i < duration * 1000L; i += tone * 2) {
  12. digitalWrite(Piezo, HIGH);
  13. delayMicroseconds(tone);
  14. digitalWrite(Piezo, LOW);
  15. delayMicroseconds(tone);
  16. }
  17. }
  18. void playNote(char note, int duration) {
  19. char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C','B'};
  20. int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956, 27.5};
  21.  
  22. // play the tone corresponding to the note name
  23. for (int i = 0; i < 8; i++) {
  24. if (names[i] == note) {
  25. playTone(tones[i], duration);
  26. }
  27. }
  28.  
  29. }
  30. void setup() {
  31. pinMode(Piezo, OUTPUT);
  32. lcd.begin (16,2);
  33. }
  34. void loop() {
  35. for (int i = 0; i < length; i++) {
  36. if (notes[i] == ' ')
  37. {
  38. delay(beats[i] * tempo); // rest
  39. } else {
  40. playNote(notes[i], beats[i] * tempo);
  41. }
  42.  
  43. // pause between notes
  44. delay(tempo / 310);
  45. }
  46. lcd.clear();
  47. for (int i = 0; i<16; i++)
  48. {
  49. lcd.setCursor(i,0);
  50. lcd.print ("Merry christmas");
  51. delay (200);
  52. lcd.clear();
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment