From d6ed3d74091b7ebafe10810f251b3c10514c3db2 Mon Sep 17 00:00:00 2001 From: dennisdebel Date: Tue, 8 Oct 2019 10:10:24 +0200 Subject: [PATCH] Added oscillator with trigger --- .../simple-osc-with-trigger.ino | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 basics/simple-osc-with-trigger/simple-osc-with-trigger.ino diff --git a/basics/simple-osc-with-trigger/simple-osc-with-trigger.ino b/basics/simple-osc-with-trigger/simple-osc-with-trigger.ino new file mode 100644 index 0000000..1507ff8 --- /dev/null +++ b/basics/simple-osc-with-trigger/simple-osc-with-trigger.ino @@ -0,0 +1,48 @@ +/* + * + * Simple (PWM) Oscillator with Trigger + * + * A2 = pitch + * A1 = note duration + * A3 = trigger in + * + * + */ + +bool triggered; // logic: trigered, yes or no +#define SPEAKER_PIN 11 +int noteDuration = 100; + +void setup() { + // set pin 11 as output + pinMode(SPEAKER_PIN, OUTPUT); + Serial.begin(9600); // debugging (see if trigger is registered) +} + +void loop() { + int input3 = digitalRead(A3); // read analog pin 3 (trigger) + int noteDuration = analogRead(A1)/10; // read analog pin 1 (note duration) + + // trigger + if(input3 && !triggered) { + Serial.println("I hear a trigger!"); + Serial.println(noteDuration); + + for(int i=0;i