Automated Blinds Controller, can be activated with pushbutton, or at time set by a slider switch

Dependencies:   Motor TextLCD mbed

Files at this revision

API Documentation at this revision

Comitter:
mmujica6
Date:
Thu Oct 17 05:47:51 2013 +0000
Commit message:
Automatic Blinds Controller;

Changed in this revision

Motor.lib Show annotated file Show diff for this revision Revisions of this file
TextLCD.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Motor.lib	Thu Oct 17 05:47:51 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/Motor/#f265e441bcd9
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Thu Oct 17 05:47:51 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/TextLCD/#44f34c09bd37
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Oct 17 05:47:51 2013 +0000
@@ -0,0 +1,81 @@
+// Sweep the motor speed from full-speed reverse (-1.0) to full speed forwards (1.0)
+ 
+#include "mbed.h"
+#include "Motor.h"
+#include "TextLCD.h"
+
+Motor m(p21, p23, p28); // pwm, fwd, rev
+DigitalOut led(LED1);
+TextLCD lcd(p14, p16, p17, p18, p19, p20, TextLCD::LCD20x4); // rs, e, d4-d7
+DigitalOut high(p22);
+DigitalIn pb(p6);
+DigitalOut high2(p29); 
+AnalogIn slider(p15);
+Serial pc(USBTX, USBRX);
+void open();
+void close();
+void printTime(double);
+int state;
+char buffer[32];
+time_t seconds;
+double setTime;
+struct tm* timeInfo;
+
+int main() {
+    set_time(    702000900    );  
+    state = 1; //Start with blinds closed (0 is open)
+    pb.mode(PullUp);
+    int lastPb = pb;
+    lcd.cls();
+    wait(1);
+    while (1){
+        seconds = time(NULL);
+        if (abs(slider-setTime)>.01){
+            setTime = slider;
+        }
+        printTime(setTime);
+        high = 1;
+        high2 = 1;
+        if (!pb){
+            if (state == 1){
+                open();
+                led = 1;
+                pc.printf("open");
+            }
+            else {
+                close();
+                led = 0;
+                pc.printf("close");
+            }
+        }
+        m.speed(0);
+        wait(.2);
+    }
+}
+
+void open() {
+    m.speed(-1);
+    wait(2.6);
+    state = 0;
+}
+
+void close() {
+    m.speed(1);
+    wait(2.6);
+    state = 1;
+}
+
+// Takes analog input from 0 to 1 and displays a time based on that
+void printTime(double in) {
+    int totMins = in*1440; //maps to integer based on mins in a day
+    int hrs = totMins/60;
+    int mins = totMins%60;
+    timeInfo = localtime(&seconds);
+    lcd.locate(0,0);
+    lcd.printf("%d:%d",timeInfo->tm_hour,timeInfo->tm_min);
+    lcd.locate(0,1);
+    lcd.printf("%d:%d",hrs,mins);
+    if ((state == 1) && (hrs == timeInfo->tm_hour) && (mins == timeInfo->tm_min)){
+        open();
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Oct 17 05:47:51 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/a9913a65894f
\ No newline at end of file