summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sketch_receiver/sketch_receiver.ino72
1 files changed, 51 insertions, 21 deletions
diff --git a/sketch_receiver/sketch_receiver.ino b/sketch_receiver/sketch_receiver.ino
index 614e120..4bc1563 100644
--- a/sketch_receiver/sketch_receiver.ino
+++ b/sketch_receiver/sketch_receiver.ino
@@ -4,9 +4,13 @@
RCSwitch sender = RCSwitch( );
LiquidCrystal lcd = LiquidCrystal(8 ,9 ,4 ,5 ,6 ,7);
+//Sender
#define CodeLength 24
#define SendPin A5
+const unsigned long OnCode[2] = {1381717, 1394005};
+const unsigned long OffCode[2] = {1381716, 1394004};
+
//Sonic sensor
#define trigPin A2
#define echoPin A1
@@ -17,19 +21,34 @@ LiquidCrystal lcd = LiquidCrystal(8 ,9 ,4 ,5 ,6 ,7);
int keyLimits [KEY_COUNT+1] = {100, 330, 580, 900, 1023};
int keyNames [KEY_COUNT+1] = {0, 1, 2, 3, 4};
-const unsigned long OnCode[2] = {1381717, 1394005};
-const unsigned long OffCode[2] = {1381716, 1394004};
+//Timer
+unsigned long timeLastSeen = 0;
+bool sonicPriority = false;
+
+
+
+
+/*
+ *Camil Staps, s4498062
+ *Robin Immel, s4372891
+ *Arduino:
+ * 3.3V
+ *Sender connected to
+ * Data : A5
+ *Ultrasonic connected to:
+ * Echo : A1
+ * Trig : A2
+ *
+ *LCD shield connected to:
+ * Arduino
+ */
+
void setup() {
lcd.begin(16,2);
- Serial.begin(9600);
- Serial.println("RC receiver");
- mySwitch.enableReceive(0); // Receiver on interrupt 0 => that is pin #2
-
pinMode(SendPin, OUTPUT);
sender.enableTransmit(SendPin);
sender.setProtocol(1);
- Serial.begin (9600);
pinMode(trigPin, OUTPUT) ;
pinMode(echoPin, INPUT) ;
}
@@ -39,7 +58,7 @@ void setSocket(int id, bool on) {
lcd.setCursor(0, id);
lcd.print("Socket ");
lcd.print(id);
- lcd.print(on ? " on" : " off");
+ lcd.print(on ? " on " : " off");
}
void button_left(){
@@ -69,29 +88,40 @@ int check_button(){
return keyNames[i];
}
-bool smaller_than(){
+bool object_close(){
digitalWrite(trigPin, HIGH) ;
delayMicroseconds(10);
digitalWrite(trigPin, LOW) ;
int duration = pulseIn(echoPin, HIGH) ;
- lcd.setCursor(0,1);
- lcd.print((duration / 2) / 29);
return (((duration / 2) / 29) < 100);
}
void loop() {
-
- switch (check_button()) {
- case 0: button_right(); break;
- case 1: button_up(); break;
- case 2: button_down(); break;
- case 3: button_left(); break;
-
- }
-
- if(smaller_than()){
+ bool trigger = object_close();
+ //Als er iets gezien wordt in de laatste 5 seconde, gaan de lampen aan.
+ if(trigger || millis() < timeLastSeen + 5000){
setSocket(0,true);
setSocket(1,true);
+
+ if (trigger)
+ timeLastSeen = millis();
+
+ sonicPriority = true;
+ }
+ //Anders als er ooit iets gezien is, maar niet de laatste 5 seconden gaan de stopcontacten uit.
+ else if (sonicPriority) {
+ setSocket(0, false);
+ setSocket(1, false);
+ sonicPriority = false;
+ }
+ //Anders kan men de stopcontacten aan/uit zetten met de knopjes.
+ else {
+ switch (check_button()) {
+ case 0: button_right(); break;
+ case 1: button_up(); break;
+ case 2: button_down(); break;
+ case 3: button_left(); break;
+ }
}