//Main Ardiuno #include #include Servo myServo; int green = 3; int yellow = 4; int red = 5; int light = 6; int motion= 7; int sound = 2; int x = 0; void setup() { Wire.begin(); Serial.begin(9600); pinMode(green, OUTPUT); pinMode(yellow, OUTPUT); pinMode(red, OUTPUT); pinMode(light, OUTPUT); pinMode(motion, INPUT); pinMode(sound, OUTPUT); myServo.attach(9); } void sensor(){ int motionState = digitalRead(motion); if(red == 5){ if(motionState == 1){ camera();} } } void camera(){ digitalWrite(light, HIGH); digitalWrite(sound , HIGH); delay(100); digitalWrite(light, LOW); digitalWrite(sound , LOW); Serial.print("SOMEONE RAN THE LIGHT");} void servoBarricadeDown(){ myServo.write(90);} void servoBarricadeUp(){ myServo.write(0);} void transmission(){ Wire.beginTransmission(1); x = digitalRead(red); Wire.write(red); Wire.endTransmission(1); } void loop(){ transmission(); servoBarricadeDown(); digitalWrite(red, HIGH); sensor(); delay(3500); digitalWrite(red, LOW); servoBarricadeUp(); digitalWrite(yellow, HIGH); delay(3000); digitalWrite(yellow, LOW); digitalWrite(green, HIGH); delay(3000); digitalWrite(green, LOW); } // 2nd Arduino #include int a = 12; int b =13; int c = 4; int d = 3; int e = 2; int f = 11; int g = 10; int x; int red = 5; void setup() { Wire.begin(1); Wire.onReceive(receiveEvent); pinMode(a, OUTPUT); pinMode(b, OUTPUT); pinMode(c, OUTPUT); pinMode(d, OUTPUT); pinMode(e, OUTPUT); pinMode(f, OUTPUT); pinMode(g, OUTPUT);} void loop() { delay(100); } void receiveEvent(int howMany){ x = Wire.read(); if (x == 5){ nine(); delay(20000); eight(); delay(20000); seven(); delay(20000); six(); delay(20000); five(); delay(20000); four(); delay(20000); three(); delay(20000); two(); delay(20000); one(); delay(20000); zero(); delay(20000);} } void zero(){ digitalWrite(a, LOW); digitalWrite(b, LOW); digitalWrite(c, LOW); digitalWrite(d, LOW); digitalWrite(e, LOW); digitalWrite(f, LOW); digitalWrite(g, HIGH);} void one(){ digitalWrite(a, HIGH); digitalWrite(b, LOW); digitalWrite(c, LOW); digitalWrite(d, HIGH); digitalWrite(e, HIGH); digitalWrite(f, HIGH); digitalWrite(g, HIGH);} void two(){ digitalWrite(a, LOW); digitalWrite(b, LOW); digitalWrite(c, HIGH); digitalWrite(d, LOW); digitalWrite(e, LOW); digitalWrite(f, HIGH); digitalWrite(g, LOW);} void three(){ digitalWrite(a, LOW); digitalWrite(b, LOW); digitalWrite(c, LOW); digitalWrite(d, LOW); digitalWrite(e, HIGH); digitalWrite(f, HIGH); digitalWrite(g, LOW);} void four(){ digitalWrite(a, HIGH); digitalWrite(b, LOW); digitalWrite(c, LOW); digitalWrite(d, HIGH); digitalWrite(e, HIGH); digitalWrite(f, LOW); digitalWrite(g, LOW);} void five(){ digitalWrite(a, LOW); digitalWrite(b, HIGH); digitalWrite(c, LOW); digitalWrite(d, LOW); digitalWrite(e, HIGH); digitalWrite(f, LOW); digitalWrite(g, LOW);} void six(){ digitalWrite(a, LOW); digitalWrite(b, HIGH); digitalWrite(c, LOW); digitalWrite(d, LOW); digitalWrite(e, LOW); digitalWrite(f, LOW); digitalWrite(g, LOW);} void seven(){ digitalWrite(a, LOW); digitalWrite(b, LOW); digitalWrite(c, LOW); digitalWrite(d, HIGH); digitalWrite(e, HIGH); digitalWrite(f, HIGH); digitalWrite(g, HIGH);} void eight(){ digitalWrite(a, LOW); digitalWrite(b, LOW); digitalWrite(c, LOW); digitalWrite(d, LOW); digitalWrite(e, LOW); digitalWrite(f, LOW); digitalWrite(g, LOW);} void nine(){ digitalWrite(a, LOW); digitalWrite(b, LOW); digitalWrite(c, LOW); digitalWrite(d, HIGH); digitalWrite(e, HIGH); digitalWrite(f, LOW); digitalWrite(g, LOW);}