You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.6 KiB
Arduino

5 years ago
/*
*
* Snare
*
*/
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));
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() {
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))
}
delay(analogRead(A2)); //fake 'trigger'
Serial.println(analogRead(A2));
}