Core studio environments spring 2015 – PIR GAME
Devices:
PIR sensor, Soft Touch-Panel Potentiometer, potentiometer, green LED, red LED, a buzzer, a pull down resistor. Bunch of wires.
They’re smartly wired.
I thought it would be really difficult so after I finished every phrases I thought I did it wrong…
Actually it really help me to pick up Arduino after I didn’t play with it during the whole winter vacation.
Play the video here!::: “PLAY ME!”
ATTENTION: I got the bonus… a piece of cake.
——–Below are data from Serial monitor—————-
Tick…Tick…
GO!!!!
899
500
Tick…Tick…
GO!!!!
Tick…Tick…
GO!!!!
Tick…Tick…
GO!!!!
Tick…Tick…
GO!!!!
Tick…Tick…
GO!!!!
Tick…Tick…
U sucks!
Board Cooling Countdown:9s.
Board Cooling Countdown:8s.
Board Cooling Countdown:7s.
Board Cooling Countdown:6s.
Board Cooling Countdown:5s.
Board Cooling Countdown:4s.
Board Cooling Countdown:3s.
Board Cooling Countdown:2s.
Board Cooling Countdown:1s.
Board Cooling Countdown:0s.
GO!!!!
Tick…Tick…
GO!!!!
Tick…Tick…
Win!
Board Cooling Countdown:9s.
Board Cooling Countdown:8s.
Board Cooling Countdown:7s.
Board Cooling Countdown:6s.
Board Cooling Countdown:5s.
Board Cooling Countdown:4s.
Board Cooling Countdown:3s.
Board Cooling Countdown:2s.
Board Cooling Countdown:1s.
Board Cooling Countdown:0s.
GO!!!!
Tick…Tick…
GO!!!!
Tick…Tick…
GO!!!!
Tick…Tick…
Win!
Board Cooling Countdown:9s.
Board Cooling Countdown:8s.
Board Cooling Countdown:7s.
Board Cooling Countdown:6s.
Board Cooling Countdown:5s.
Board Cooling Countdown:4s.
Board Cooling Countdown:3s.
Board Cooling Countdown:2s.
Board Cooling Countdown:1s.
Board Cooling Countdown:0s.
GO!!!!
Tick…Tick…
GO!!!!
Tick…Tick…
GO!!!!
Tick…Tick…
GO!!!!
Tick…Tick…
GO!!!!
Tick…Tick…
————Below is whole piece of code, all original————–
//delay is 6s
const int digitalInPin = 8; // Motion detector digital in
const int armedLedPin = 3; // LED showing armed state of motion detector
const int motionLedPin = 2; // LED showing motion detector read state
int x=10;
int pace=500;
int buzz=5;
int pot1,pot2;//for anolog 1 & 2
int waitadj,waitadj2,pace2;
void setup(){
Serial.begin(9600);
pinMode(motionLedPin, OUTPUT);
pinMode(armedLedPin, OUTPUT);
pinMode(buzz, OUTPUT);
digitalWrite (armedLedPin, HIGH);
digitalWrite (motionLedPin, LOW);
randomSeed(analogRead(A0));
}
void adjust(){
pot1=analogRead(A1);
pot1=analogRead(A2);
//for the pace
pace=map(pot1,0,1024,100,900);
waitadj=map(pot2,0,1024,500,2000);
//BONUS HERE!
if(pace!=pace2){
Serial.println(pace);
}
if(waitadj!=waitadj2){
Serial.println(waitadj);
}
waitadj2=waitadj;
pace2=pace;
}
void loop(){
tick();
if(random(0, 10) == 0) {
int motion=motionRead(8,waitadj);
// Serial.println(motion);
if(motion==0){
failFunction();
rearm();
}
else if(motion==1){
winFunction();
rearm();
}
}
go();
adjust();
}
void tick(){
Serial.println(“Tick…Tick…”);
tone(buzz, 4000, 5);
tone(buzz, 3000, 10);
delay(pace);
}
void go(){
Serial.println(“GO!!!!”);
tone(buzz, 1000, 1000);
}
void winFunction(){
digitalWrite(motionLedPin,HIGH);
Serial.println(“Win!”);
tone(buzz, 3000, 200);
delay(200);
tone(buzz, 2000, 100);
digitalWrite(motionLedPin,LOW);
}
void failFunction(){
Serial.println(“U sucks!”);
tone(buzz, 100, 1000);
delay(1000);
}
void rearm(){
digitalWrite(armedLedPin,LOW);
for(int i=1;i<x+1;i++){
Serial.print(“Board Cooling Countdown:”);
Serial.print(x-i);
Serial.println(“s.”);
delay(1000);
}
digitalWrite(armedLedPin,HIGH);
}
int motionRead(int pin, int wait){
delay(wait);
int result=digitalRead(pin);
return result;
}