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