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.

94 lines
1.6 KiB
C++

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);
}