shapingthings

Simple Piezo Example

Jan 17th, 2017
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. // Pin 13 has an LED connected on most Arduino boards.
  2. // give it a name:
  3.  
  4. int sounds[] = {128, 300, 500, 800};
  5. int del = 800;
  6.  
  7. // the setup routine runs once when you press reset:
  8. void setup() {
  9. // initialize the digital pin as an output.
  10.  
  11. Serial.begin(9600);
  12.  
  13. }
  14.  
  15. // the loop routine runs over and over again forever:
  16. void loop() {
  17.  
  18. int length = 4;
  19.  
  20. for(int i=0; i < length; i++)
  21. {
  22. // print the results to the serial monitor:
  23. Serial.print("i = ");
  24. Serial.print(i);
  25. Serial.print("\t sounds = ");
  26. Serial.println(sounds[i]);
  27.  
  28. // write the sound to the pin via pwm
  29. analogWrite(6, sounds[i]);
  30. delay(del);
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment