Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int pitch = 100;
- int potValue;
- // Pin Belegung
- const int potPin = 0;
- const int piezoPin = 3;
- const int leftBtn = 11;
- const int middleBtn = 10;
- const int rightBtn = 9;
- void setup() {
- pinMode(piezo, OUTPUT);
- pinMode(leftBtn, INPUT);
- pinMode(middleBtn, INPUT);
- pinMode(rightBtn, INPUT);
- }
- void loop() {
- potValue = analogRead(potPin);
- pitch = 0;
- // Testen ob Knöpfe gedrückt sind
- if (digitalRead(leftBtn) == HIGH) {
- pitch = 200;
- }
- if (digitalRead(middleBtn) == HIGH) {
- pitch = 400;
- }
- if (digitalRead(rightBtn) == HIGH) {
- pitch = 600;
- }
- // Wenn keine Taste gedrückt ist (Pitch=0), Spiele auch keinen Ton
- if (pitch != 0) {
- tone(piezoPin, pitch + potValue);
- } else {
- noTone(piezoPin);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement