added white noise with trigger and white noise auto loop

master
Mark van den Heuvel 5 years ago
commit ec2c5601e0

@ -0,0 +1,47 @@
/*
*
* Trigger Detect
*
*
* Detecting triggers is essential to interact with other modules, for example to generate short bursts of sounds
* Try the output of simple-lfo.ino with this patch and open the serial monitor to see what happens!
*
* A3 = Trigger in
*
*/
bool triggered; // logic: trigered, yes or no
long randNumber; //variable to store random number
int pwmPin = 11; //define output pin, Meergranen output pin is 11
void setup() {
pinMode(pwmPin,OUTPUT);
Serial.begin(9600); // debugging (see if trigger is registered)
}
void loop() {
int input3 = digitalRead(A3); // read analog pin 3
// trigger
if(input3 && !triggered) { //if there is a reading on input3 and the bool condition triggered is not true do
Serial.println("I hear a trigger!");
// DO SOMETHING ON TRIGGER HERE
for(int i=0;i<2000;i++){
randNumber = random(10, 100); //generate random number between 10 and 100
digitalWrite(pwmPin, LOW); //set output pin to LOW (0v)
delayMicroseconds(randNumber);//wait for randomNumber (10-100 Mircroseconds (0.00001-0.0001 seconds))
digitalWrite(pwmPin, HIGH); //set output pin to HIGH (5v)
delayMicroseconds(randNumber); //wait for randomNumber (10-100 Mircroseconds (0.00001-0.0001 seconds))
triggered = true;
}
}
else if(!input3 && triggered) { //if there is no reading on input3 and condition triggered is true (aka sound is playing), set triggered to false, aka stop playing
// STOP WHEN NO TRIGGER IS PRESENT (or do something else ;)
triggered = false;
}
}

@ -0,0 +1,49 @@
/*
*
* Snare - External trigger
*
*/
long randNumber; //variable to store random number
int pwmPin = 11; //define output pin, Meergranen output pin is 11
bool triggered; // logic: trigered, yes or no
void setup() {
// if analog input pin 5 is unconnected, random analog
// noise will cause the call to randomSeed() to generate
// different seed numbers each time the sketch runs.
// randomSeed() will then shuffle the random function.
randomSeed(analogRead(5));
Serial.begin(9600);
pinMode(pwmPin,OUTPUT); //set pwmPin to output mode (otherwise the built-in pulldown resistor sets it as input, aka you wont hear anything)
}
void loop() {
int input3 = digitalRead(A3); // read analog pin 3
if(input3 && !triggered) { //if there is a reading on input3 and the bool condition triggered is not true do
for(int i=0;i<25;i++){
randNumber = random(10, 100); //generate random number between 10 and 100
digitalWrite(pwmPin, LOW); //set output pin to LOW (0v)
delayMicroseconds(randNumber/10*(i/4)*(analogRead(A1)/10));//wait for randomNumber (10-100 Mircroseconds (0.00001-0.0001 seconds))
digitalWrite(pwmPin, HIGH); //set output pin to HIGH (5v)
delayMicroseconds(randNumber/10*(i/4)*(analogRead(A1)/10)); //wait for randomNumber (10-100 Mircroseconds (0.00001-0.0001 seconds))
}
for(int i=0;i<200;i++){
randNumber = random(10, 100); //generate random number between 10 and 100
digitalWrite(pwmPin, LOW); //set output pin to LOW (0v)
delayMicroseconds(randNumber);//wait for randomNumber (10-100 Mircroseconds (0.00001-0.0001 seconds))
digitalWrite(pwmPin, HIGH); //set output pin to HIGH (5v)
delayMicroseconds(randNumber); //wait for randomNumber (10-100 Mircroseconds (0.00001-0.0001 seconds))
}
triggered = true;
}
else if(!input3 && triggered) { //if there is no reading on input3 and condition triggered is true (aka sound is playing), set triggered to false, aka stop playing
// STOP WHEN NO TRIGGER IS PRESENT (or do something else ;)
triggered = false;
}
}

@ -13,12 +13,26 @@
bool triggered; // logic: trigered, yes or no
long randNumber; //variable to store random number
int pwmPin = 11; //define output pin, Meergranen output pin is 11
void setup() {
Serial.begin(9600); // debugging (see if trigger is registered)
// if analog input pin 5 is unconnected, random analog
// noise will cause the call to randomSeed() to generate
// different seed numbers each time the sketch runs.
// randomSeed() will then shuffle the random function.
randomSeed(analogRead(5));
pinMode(pwmPin,OUTPUT); //set pwmPin to output mode (otherwise the built-in pulldown resistor sets it as input, aka you wont hear anything)
}
void loop() {
randNumber = random(10, 100); //generate random number between 10 and 100
digitalWrite(pwmPin, LOW); //set output pin to LOW (0v)
delayMicroseconds(randNumber);//wait for randomNumber (10-100 Mircroseconds (0.00001-0.0001 seconds))
digitalWrite(pwmPin, HIGH); //set output pin to HIGH (5v)
delayMicroseconds(randNumber); //wait for randomNumber (10-100 Mircroseconds (0.00001-0.0001 seconds))
}
int input3 = digitalRead(A3); // read analog pin 3

@ -0,0 +1,29 @@
/*
*
* White Noise Generator (simple)
*
*/
long randNumber; //variable to store random number
int pwmPin = 11; //define output pin, Meergranen output pin is 11
void setup() {
// if analog input pin 5 is unconnected, random analog
// noise will cause the call to randomSeed() to generate
// different seed numbers each time the sketch runs.
// randomSeed() will then shuffle the random function.
randomSeed(analogRead(5));
pinMode(pwmPin,OUTPUT); //set pwmPin to output mode (otherwise the built-in pulldown resistor sets it as input, aka you wont hear anything)
}
void loop() {
for(int i=0;i<100;i++){
randNumber = random(100, 1000); //generate random number between 10 and 100 /// random(analogRead(A1));
digitalWrite(pwmPin, LOW); //set output pin to LOW (0v)
delayMicroseconds(randNumber);//wait for randomNumber (10-100 Mircroseconds (0.00001-0.0001 seconds))
digitalWrite(pwmPin, HIGH); //set output pin to HIGH (5v)
delayMicroseconds(randNumber); //wait for randomNumber (10-100 Mircroseconds (0.00001-0.0001 seconds))
}
delay(analogRead(A2)); //fake trigger: delay (1000); it just pauses the code
}

@ -22,4 +22,7 @@ void loop() {
delayMicroseconds(randNumber);//wait for randomNumber (10-100 Mircroseconds (0.00001-0.0001 seconds))
digitalWrite(pwmPin, HIGH); //set output pin to HIGH (5v)
delayMicroseconds(randNumber); //wait for randomNumber (10-100 Mircroseconds (0.00001-0.0001 seconds))
delay (1000)
}

Loading…
Cancel
Save