arduino code for 2 different sounds triggered by 2 different inputs
parent
edb84a99ad
commit
6d5a0d61a2
@ -0,0 +1,93 @@
|
||||
bool onetriggered;
|
||||
bool twotriggered;
|
||||
|
||||
long randNumber;
|
||||
int pwmPin = 11;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
Serial.println("Hello");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
int Trigger1 = analogRead(A0);
|
||||
int Trigger2 = analogRead(A3);
|
||||
|
||||
Serial.println(Trigger1);
|
||||
Serial.print(" ");
|
||||
Serial.println(Trigger2);
|
||||
Serial.print(" ");
|
||||
|
||||
|
||||
|
||||
|
||||
//INPUT 0
|
||||
if(Trigger1>100 && !onetriggered) {
|
||||
|
||||
for(int i=0;i<25;i++){
|
||||
randNumber = random(10, 200);
|
||||
digitalWrite(pwmPin, LOW);
|
||||
delayMicroseconds(randNumber/10*(i/4)*(analogRead(A1)/10));
|
||||
digitalWrite(pwmPin, HIGH);
|
||||
delayMicroseconds(randNumber/10*(i/4)*(analogRead(A1)/10));
|
||||
}
|
||||
for(int i=0;i<200;i++){
|
||||
randNumber = random(10, 100);
|
||||
digitalWrite(pwmPin, LOW);
|
||||
delayMicroseconds(randNumber);
|
||||
digitalWrite(pwmPin, HIGH);
|
||||
delayMicroseconds(randNumber);
|
||||
}
|
||||
|
||||
onetriggered = true;
|
||||
Serial.println("1triggered");
|
||||
}
|
||||
|
||||
else if(Trigger1<100 && onetriggered) {
|
||||
noTone(11);
|
||||
onetriggered = false;
|
||||
|
||||
Serial.println("1nope");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// INPUT 3
|
||||
if(Trigger2>700 && !twotriggered) {
|
||||
|
||||
for(int i=0;i<9;i++){
|
||||
analogWrite(11,255);
|
||||
analogWrite(11,0);
|
||||
delayMicroseconds(analogRead(A2)*i);
|
||||
analogWrite(11,255);
|
||||
delayMicroseconds(analogRead(A2)*i);
|
||||
analogWrite(11,0);
|
||||
}
|
||||
|
||||
for(int i=0;i<2;i++){
|
||||
analogWrite(11,255);
|
||||
delayMicroseconds(analogRead(A2)*i);
|
||||
analogWrite(11,0);
|
||||
delay(1);
|
||||
}
|
||||
|
||||
twotriggered = true;
|
||||
|
||||
Serial.println("2triggered");
|
||||
}
|
||||
|
||||
else if(Trigger2<700 && twotriggered) {
|
||||
noTone(11);
|
||||
twotriggered = false;
|
||||
|
||||
Serial.println("2nope");
|
||||
}
|
||||
|
||||
|
||||
|
||||
delay(10);
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
bool onetriggered;
|
||||
bool twotriggered;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
Serial.println("Hello");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
int Trigger1 = analogRead(A0);
|
||||
int Trigger2 = analogRead(A3);
|
||||
|
||||
Serial.println(Trigger1);
|
||||
Serial.print(" ");
|
||||
Serial.println(Trigger2);
|
||||
Serial.print(" ");
|
||||
|
||||
//INPUT 0
|
||||
if(Trigger1>100 && !onetriggered) {
|
||||
tone(11, 80);
|
||||
onetriggered = true;
|
||||
|
||||
Serial.println("1triggered");
|
||||
}
|
||||
|
||||
else if(Trigger1<100 && onetriggered) {
|
||||
noTone(11);
|
||||
onetriggered = false;
|
||||
|
||||
Serial.println("1nope");
|
||||
}
|
||||
|
||||
|
||||
// INPUT 3
|
||||
if(Trigger2>700 && !twotriggered) {
|
||||
tone(11, 120);
|
||||
twotriggered = true;
|
||||
|
||||
Serial.println("2triggered");
|
||||
}
|
||||
|
||||
else if(Trigger2<700 && twotriggered) {
|
||||
noTone(11);
|
||||
twotriggered = false;
|
||||
|
||||
Serial.println("2nope");
|
||||
}
|
||||
|
||||
|
||||
|
||||
delay(50);
|
||||
}
|
Loading…
Reference in New Issue