Guest User

Untitled

a guest
Dec 11th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. int speakerPin = 9;
  2. int length = 1;
  3. char notes[] = "c";
  4. int beats[] = {1};
  5. int tempo = 125;
  6.  
  7. void playTone(int tone, int duration)
  8. {
  9. for (long i = 0; 1 < duration * 1000L; i += tone * 2)
  10. {
  11. digitalWrite(speakerPin, HIGH);
  12. delayMicroseconds(tone);
  13. digitalWrite(speakerPin, LOW);
  14. delayMicroseconds(tone);
  15. }
  16. }
  17.  
  18. void playNote(char note, int duration)
  19. {
  20. char names[] = {'c'};
  21. int tones[] = {1915};
  22. for (int i = 0; i < 8; i++)
  23. {
  24. if (names[i] == note)
  25. {
  26. playTone(tones[i], duration);
  27. }
  28. }
  29. }
  30.  
  31.  
  32. void setup()
  33. {
  34. pinMode(13, OUTPUT);
  35. pinMode(12, OUTPUT);
  36. pinMode(11, OUTPUT);
  37. pinMode(10, OUTPUT);
  38. pinMode(speakerPin, OUTPUT);
  39. }
  40.  
  41. void loop() {
  42.  
  43. for (int i = 0; i < length; i++)
  44. {
  45. if (notes[i] == 'c')
  46. {
  47. playNote(notes[i], beats[i] * tempo);
  48. delay(beats[i] * tempo);
  49. delay(tempo / 2);
  50.  
  51. digitalWrite(13, HIGH);
  52. delay(50);
  53. digitalWrite(12, HIGH);
  54. delay(50);
  55. digitalWrite(11, HIGH);
  56. delay(50);
  57. digitalWrite(10, HIGH);
  58. delay(50);
  59. digitalWrite(13, LOW);
  60. delay(50);
  61. digitalWrite(12, LOW);
  62. delay(50);
  63. digitalWrite(11, LOW);
  64. delay(50);
  65. digitalWrite(10, LOW);
  66. delay(50);
  67. }
  68. }
  69. }
Add Comment
Please, Sign In to add comment