ccarman602

Project-1

Nov 25th, 2021
548
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Music Dynamic Rhythm Lamp
  2. #define NTD0 -1
  3. #define NTD1 294
  4. #define NTD2 330
  5. #define NTD3 350
  6. #define NTD4 393
  7. #define NTD5 441
  8. #define NTD6 495
  9. #define NTD7 556
  10.  
  11. #define NTDL1 147
  12. #define NTDL2 165
  13. #define NTDL3 175
  14. #define NTDL4 196
  15. #define NTDL5 221
  16. #define NTDL6 248
  17. #define NTDL7 278
  18.  
  19. #define NTDH1 589
  20. #define NTDH2 661
  21. #define NTDH3 700
  22. #define NTDH4 786
  23. #define NTDH5 882
  24. #define NTDH6 990
  25. #define NTDH7 112
  26.  
  27. #define WHOLE 1
  28. #define HALF 0.5
  29. #define QUARTER 0.25
  30. #define EIGHTH 0.25
  31. #define SIXTEENTH 0.625
  32.  
  33. int tune[]=
  34. {
  35. NTD3,NTD3,NTD4,NTD5,
  36. NTD5,NTD4,NTD3,NTD2,
  37. NTD1,NTD1,NTD2,NTD3,
  38. NTD3,NTD2,NTD2,
  39. NTD3,NTD3,NTD4,NTD5,
  40. NTD5,NTD4,NTD3,NTD2,
  41. NTD1,NTD1,NTD2,NTD3,
  42. NTD2,NTD1,NTD1,
  43. NTD2,NTD2,NTD3,NTD1,
  44. NTD2,NTD3,NTD4,NTD3,NTD1,
  45. NTD2,NTD3,NTD4,NTD3,NTD2,
  46. NTD1,NTD2,NTDL5,NTD0,
  47. NTD3,NTD3,NTD4,NTD5,
  48. NTD5,NTD4,NTD3,NTD4,NTD2,
  49. NTD1,NTD1,NTD2,NTD3,
  50. NTD2,NTD1,NTD1
  51. };
  52.  
  53. float durt[]=
  54. {
  55. 1,1,1,1,
  56. 1,1,1,1,
  57. 1,1,1,1,
  58. 1+0.5,0.5,1+1,
  59. 1,1,1,1,
  60. 1,1,1,1,
  61. 1,1,1,1,
  62. 1+0.5,0.5,1+1,
  63. 1,1,1,1,
  64. 1,0.5,0.5,1,1,
  65. 1,0.5,0.5,1,1,
  66. 1,1,1,1,
  67. 1,1,1,1,
  68. 1,1,1,0.5,0.5,
  69. 1,1,1,1,
  70. 1+0.5,0.5,1+1,
  71. };
  72.  
  73. int length;
  74. int tonepin=5;
  75. int ledp=4;
  76.  
  77. void setup()
  78. {
  79.   pinMode(tonepin,OUTPUT);
  80.   pinMode(ledp,OUTPUT);
  81.   length=sizeof(tune)/sizeof(tune[0]);
  82. }
  83.  
  84. void loop()
  85. {
  86.   for(int x=0;x<length;x++)
  87.   {
  88.     tone(tonepin,tune[x]);
  89.     digitalWrite(ledp, HIGH);
  90.     delay(400*durt[x]);
  91.     digitalWrite(ledp, LOW);
  92.     delay(100*durt[x]);
  93.     noTone(tonepin);
  94.  
  95.   }
  96.   delay(4000);
  97. }
  98.  
RAW Paste Data