/*
 * 
 * Simple (PWM) Oscillator Internal Trigger
 * 
 * A2 = pitch
 * A1 = note duration
 * A0 = LFO speed
 * 
 * 
 */

bool triggered; // logic: trigered, yes or no
#define SPEAKER_PIN 11 
int noteDuration = 100; //default duration

void setup() {
  // set pin 11 as output
  pinMode(SPEAKER_PIN, OUTPUT);

}

void loop() {


    int noteDuration = analogRead(A1)/10; // read analog pin 1 (note duration 0-100ms)
    int LFO = analogRead(A0)*2; // read analog pin 1 (note duration 0-2000ms)

     //fake trigger   
    for(int i=0;i<2;i++){

  
     for(int i=0;i<noteDuration;i++){  
        digitalWrite( SPEAKER_PIN, LOW );
        delayMicroseconds( analogRead(A2)*10); // wait 
        digitalWrite( SPEAKER_PIN, HIGH );
        delayMicroseconds( analogRead(A2)*10 ); // wait 
        triggered = true;
        delay(1); //playtime of the osc note: this numer * noteDuration milliseconds
    }
   

    delay(LFO);  //fake trigger delay

    }

}
