Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. int pitch = 100;
  2. int potValue;
  3.  
  4. // Pin Belegung
  5. const int potPin = 0;
  6. const int piezoPin = 3;
  7. const int leftBtn = 11;
  8. const int middleBtn = 10;
  9. const int rightBtn = 9;
  10.  
  11. void setup() {
  12. pinMode(piezo, OUTPUT);
  13. pinMode(leftBtn, INPUT);
  14. pinMode(middleBtn, INPUT);
  15. pinMode(rightBtn, INPUT);
  16. }
  17.  
  18. void loop() {
  19. potValue = analogRead(potPin);
  20. pitch = 0;
  21.  
  22. // Testen ob Knöpfe gedrückt sind
  23. if (digitalRead(leftBtn) == HIGH) {
  24. pitch = 200;
  25. }
  26. if (digitalRead(middleBtn) == HIGH) {
  27. pitch = 400;
  28. }
  29. if (digitalRead(rightBtn) == HIGH) {
  30. pitch = 600;
  31. }
  32. // Wenn keine Taste gedrückt ist (Pitch=0), Spiele auch keinen Ton
  33. if (pitch != 0) {
  34. tone(piezoPin, pitch + potValue);
  35. } else {
  36. noTone(piezoPin);
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement