Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of AutoBlindsController by
main.cpp
00001 // Sweep the motor speed from full-speed reverse (-1.0) to full speed forwards (1.0) 00002 00003 #include "mbed.h" 00004 #include "Motor.h" 00005 #include "TextLCD.h" 00006 00007 Motor m(p21, p23, p28); // pwm, fwd, rev 00008 DigitalOut led(LED1); 00009 DigitalOut test(LED2); 00010 TextLCD lcd(p14, p16, p17, p18, p19, p20, TextLCD::LCD20x4); // rs, e, d4-d7 00011 DigitalOut high(p22); 00012 DigitalIn pb(p6); 00013 DigitalOut high2(p29); 00014 AnalogIn slider(p15); 00015 Serial pc(USBTX, USBRX); 00016 void open(); 00017 void close(); 00018 void printTime(double); 00019 int state; 00020 char buffer[32]; 00021 time_t seconds; 00022 double setTime; 00023 struct tm* timeInfo; 00024 00025 int main() { 00026 set_time( 702000900 ); 00027 state = 1; //Start with blinds closed (0 is open) 00028 pb.mode(PullUp); 00029 int lastPb = pb; 00030 lcd.cls(); 00031 wait(1); 00032 while (1){ 00033 seconds = time(NULL); 00034 if (abs(slider.read()-setTime)>.006){ // <-- this is the line of percision 00035 setTime = slider.read(); 00036 } 00037 printTime(setTime); 00038 00039 pc.printf("%f \n", slider.read()); 00040 high = 1; //seems unused 00041 high2 = 1; //seems unused 00042 if (!pb){ 00043 if (state == 1){ 00044 open(); 00045 led = 1; 00046 pc.printf("open"); 00047 } 00048 else { 00049 close(); 00050 led = 0; 00051 pc.printf("close"); 00052 } 00053 } 00054 m.speed(0); 00055 wait(.2); 00056 } 00057 } 00058 00059 void open() { 00060 m.speed(-1); 00061 test = 1; // for testing purposes, the system should be running 00062 wait(2.6); 00063 test = 0; 00064 state = 0; 00065 } 00066 00067 void close() { 00068 m.speed(1); 00069 wait(2.6); 00070 state = 1; 00071 } 00072 00073 // Takes analog input from 0 to 1 and displays a time based on that 00074 void printTime(double in) { 00075 int totMins = in*1440; //maps to integer based on mins in a day 00076 int hrs = totMins/60; 00077 int mins = totMins%60; 00078 timeInfo = localtime(&seconds); 00079 lcd.locate(0,0); 00080 lcd.printf("time: %2.2d:%2.2d",timeInfo->tm_hour,timeInfo->tm_min); // added percision to make it more like a clock HH:MM 00081 lcd.locate(0,1); 00082 lcd.printf("start: %2.2d:%2.2d",hrs,mins); 00083 if ((state == 1) && (hrs == timeInfo->tm_hour) && (mins == timeInfo->tm_min)){ 00084 open(); 00085 } 00086 }
Generated on Fri Jul 22 2022 00:41:22 by
1.7.2
