Last active
October 10, 2016 04:10
-
-
Save timigod/952a55c9e39f74b912fe762ba9c40e5f to your computer and use it in GitHub Desktop.
Test home automation model circuit. For chunksofco.de
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Servo.h> | |
Servo frontDoor; | |
Servo garageDoor; | |
int lightDining = 11; | |
int lightOutside = 10; | |
int lightKitchen = 9; | |
int lightLivingroom = 8; | |
int servoDoor = 7; | |
int servoGarage = 6; | |
void light(int ledPin, bool on) { | |
Serial.println("led"); | |
if (on) { | |
digitalWrite(ledPin, HIGH); | |
} else { | |
digitalWrite(ledPin, LOW); | |
} | |
} | |
void on() { | |
light(lightDining, true); | |
light(lightOutside, true); | |
light(lightKitchen, true); | |
light(lightLivingroom, true); | |
} | |
void off() { | |
light(lightDining, false); | |
light(lightOutside, false); | |
light(lightKitchen, false); | |
light(lightLivingroom, false); | |
} | |
void blink(int delayn, int count) { | |
for (int j = 0; j <= count; j++) { | |
on(); | |
delay(delayn); | |
off(); | |
delay(delayn); | |
} | |
} | |
void open() { | |
door(1); | |
garage(1); | |
} | |
void close() { | |
door(0); | |
garage(0); | |
} | |
void garage(bool open) { | |
Serial.println("garage"); | |
if (open) { | |
garageDoor.write(150); | |
} else { | |
garageDoor.write(80); | |
} | |
} | |
void door(bool open) { | |
Serial.println("door"); | |
if (open) { | |
frontDoor.write(80); | |
} else { | |
frontDoor.write(20); | |
} | |
} | |
void ping(int delayn) { | |
off(); | |
light(lightDining, true); | |
delay(delayn); | |
light(lightOutside, true); | |
light(lightDining, false); | |
delay(delayn); | |
light(lightOutside, false); | |
light(lightKitchen, true); | |
delay(delayn); | |
light(lightKitchen, false); | |
light(lightLivingroom, true); | |
delay(delayn); | |
delay(delayn); | |
} | |
void pong(int delayn) { | |
off(); | |
light(lightLivingroom, true); | |
delay(delayn); | |
light(lightLivingroom, false); | |
light(lightKitchen, true); | |
delay(delayn); | |
light(lightKitchen, false); | |
light(lightOutside, true); | |
delay(delayn); | |
light(lightOutside, false); | |
light(lightDining, true); | |
delay(delayn); | |
delay(delayn); | |
} | |
void pingpong(int count) { | |
for (int j = 0; j <= count; j++) { | |
ping(100); | |
pong(100); | |
} | |
} | |
void reset() { | |
garage(false); | |
door(false); | |
off(); | |
} | |
void demo() { | |
pingpong(1); | |
open(); | |
delay(500); | |
close(); | |
delay(500); | |
blink(100, 5); | |
} | |
void setup() { | |
pinMode(lightDining, OUTPUT); | |
pinMode(lightOutside, OUTPUT); | |
pinMode(lightKitchen, OUTPUT); | |
pinMode(lightLivingroom, OUTPUT); | |
frontDoor.attach(servoDoor); | |
garageDoor.attach(servoGarage); | |
demo(); | |
reset(); | |
} | |
void loop(){ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment