RGHG808
Photo Credit: Professor Daniel Sullivan
const byte POTENTIOMETER = 0; // Plugged into A0 | |
const byte CONTROL = 13; // pin # | |
int reading; | |
int value; | |
int MakeSound=0; | |
int Trap = 0; | |
int ledArray[] = {1,2,3,4,5}; //LED Array | |
int rate = 50; | |
int pause = 1; | |
int wheel = 7; | |
void setup() { | |
pinMode(CONTROL, OUTPUT); | |
pinMode(11,OUTPUT); | |
beep(50); | |
beep(50); | |
beep(50); | |
delay(1000); | |
pinMode(8,INPUT); | |
pinMode(wheel,OUTPUT); | |
for (int i=0; i<5; i++){ //LED Array | |
pinMode(ledArray[i], OUTPUT); | |
} | |
} | |
void loop() { | |
MakeSound=digitalRead(8); | |
if (MakeSound==HIGH || Trap==HIGH) | |
{ | |
Trap=1; | |
{ | |
beep(200); | |
} | |
{ | |
digitalWrite(wheel,HIGH); | |
} | |
for (int i=0; i<5; i++) | |
{ | |
digitalWrite(ledArray[i], HIGH); | |
delay(rate); | |
digitalWrite(ledArray[i], LOW); | |
if (i == 4) delay(pause*rate); | |
else delay(rate); | |
} | |
for (int j=1; j<4; j++){ | |
int k = 4-j; | |
digitalWrite(ledArray[k], HIGH); | |
delay(rate); | |
digitalWrite(ledArray[k], LOW); | |
delay(rate); | |
} | |
} | |
reading = analogRead(POTENTIOMETER); | |
value = map(reading, 0, 1024, 0, 255); | |
analogWrite(CONTROL, value); | |
} // end loop | |
void beep(unsigned char delayms){ | |
analogWrite(11, 20); // Almost any value can be used except 0 and 255 | |
// experiment to get the best tone | |
delay(delayms); // wait for a delayms ms | |
analogWrite(11, 0); // 0 turns it off | |
delay(delayms); // wait for a delayms ms | |
} |