Application where a user inputs a time and then coffee will be made
Dependencies: EthernetInterface HTTPClientAuthAndPathExtension NTPClient PinDetect mbed-rtos mbed
main.cpp
00001 #include "mbed.h" 00002 #include <string> 00003 #include <ctype.h> 00004 #include "EthernetInterface.h" 00005 #include "NTPClient.h" 00006 #include "PinDetect.h" 00007 00008 00009 00010 PinDetect override(p12); 00011 DigitalOut myled(LED1); 00012 DigitalOut led(LED2); 00013 DigitalOut on(p19); 00014 DigitalOut off(p20); 00015 Serial pc(USBTX, USBRX); 00016 struct tm *cTime; 00017 int cups = 0; 00018 int hour; 00019 int minute; 00020 int timeBrew = 120; 00021 00022 00023 00024 00025 void waitForBrew(){ 00026 00027 EthernetInterface eth; 00028 NTPClient ntp; 00029 static const char* mbedIp = "128.61.126.186"; //IP 00030 static const char* mbedMask = "255.255.240.0"; // Mask 00031 static const char* mbedGateway = "128.61.112.1"; //Gateway 00032 eth.init(mbedIp, mbedMask, mbedGateway); 00033 eth.connect(); 00034 ntp.setTime("0.pool.ntp.org"); 00035 time_t currTime = time(NULL); 00036 00037 while(1){ 00038 currTime = time(NULL); 00039 cTime = localtime(&currTime); 00040 if (minute == cTime->tm_min && hour == cTime->tm_hour){ 00041 on = 1; 00042 wait(.5); 00043 on = 0; 00044 off =0; 00045 wait(timeBrew); 00046 on = 0; 00047 off = 1; 00048 wait(.5); 00049 off = 0; 00050 } 00051 } 00052 } 00053 00054 int main() { 00055 00056 on = 0; 00057 off = 1; 00058 override.mode(PullUp); 00059 wait(0.1); 00060 off=0; 00061 00062 00063 00064 char buffer[20]; 00065 char minBuffer[2]; 00066 char hourBuf[2]; 00067 bool brewing = false; 00068 00069 00070 00071 00072 while(brewing == false){ 00073 if(pc.readable()){ 00074 myled = 0; 00075 pc.gets(buffer,6); 00076 wait(0.5); 00077 pc.printf(buffer); 00078 pc.printf("\n"); 00079 if(isdigit(buffer[0])){ 00080 led = 1; 00081 for (int k = 0;k < 2;k++){ 00082 hourBuf[k] = buffer[k]; 00083 } 00084 for(int k =3; k<6; k++){ 00085 minBuffer[k-3]=buffer[k]; 00086 } 00087 hour = atoi(hourBuf); 00088 minute = atoi(minBuffer); 00089 pc.printf("hour is %d\n",hour); 00090 pc.printf("minute is %d\n",minute); 00091 brewing = true; 00092 waitForBrew(); 00093 } 00094 else 00095 led = 0; 00096 } 00097 else 00098 myled = 1; 00099 } 00100 00101 00102 }
Generated on Fri Jul 15 2022 02:15:54 by 1.7.2