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.
Dependencies: C12832 LM75B mbed
main.cpp
00001 #include "C12832.h" 00002 #include "LM75B.h" 00003 #include <string> 00004 #include "mbed.h" 00005 00006 DigitalOut led_red (LED_RED); 00007 DigitalOut led_green (LED_GREEN); 00008 DigitalOut led_blue (LED_BLUE); 00009 00010 DigitalOut xr_led (D5); 00011 DigitalOut xg_led (D9); 00012 DigitalOut xb_led (PTC12); 00013 00014 Ticker tempSender; 00015 00016 int sw2_down, sw2_up, sw3_down, sw3_up, temp_flag; 00017 00018 C12832 lcd(D11, D13, D12, D7, D10); 00019 LM75B lm_temp (D14, D15); 00020 InterruptIn sw2_int (PTC6); /* interrupts for the two on-board switches */ 00021 InterruptIn sw3_int (PTA4); 00022 00023 Serial pc(USBTX, USBRX); 00024 00025 void parse(string buf) { 00026 if (buf.find("ldg")==0) { 00027 led_green = 1-strtod(buf.substr(3).c_str(), NULL); 00028 } 00029 else if (buf.find("ldb")==0) { 00030 led_blue = 1-strtod(buf.substr(3).c_str(), NULL); 00031 } 00032 else if (buf.find("ldr")==0) { 00033 led_red = 1-strtod(buf.substr(3).c_str(), NULL); 00034 } 00035 if (buf.find("xdg")==0) { 00036 xg_led = 1-strtod(buf.substr(3).c_str(), NULL); 00037 } 00038 else if (buf.find("xdb")==0) { 00039 xb_led = 1-strtod(buf.substr(3).c_str(), NULL); 00040 } 00041 else if (buf.find("xdr")==0) { 00042 xr_led = 1-strtod(buf.substr(3).c_str(), NULL); 00043 } 00044 else if (buf.find("lcdclr")==0) { 00045 lcd.cls(); 00046 } 00047 else if (buf.find("lcdloc")==0) { 00048 string coord = buf.substr(6); 00049 string x = buf.substr(0,buf.find(",")); 00050 string y = buf.substr(buf.find(",")); 00051 lcd.locate(atoi(x.c_str()),atoi(y.c_str())); 00052 } 00053 else if(buf.find("lcdprn")==0) { 00054 lcd.printf(buf.substr(6).c_str()); 00055 } 00056 else if(buf.find("temp")==0) { 00057 pc.printf("%f", lm_temp.read()); 00058 pc.printf(";"); 00059 } 00060 } 00061 00062 void sendTemp(void) 00063 { 00064 temp_flag = 1; 00065 } 00066 00067 void sw2Down (void) 00068 { 00069 sw2_down = 1; 00070 } 00071 00072 00073 void sw2Up (void) 00074 { 00075 sw2_up = 1; 00076 } 00077 00078 void sw3Down (void) 00079 { 00080 sw3_down = 1; 00081 } 00082 00083 00084 void sw3Up (void) 00085 { 00086 sw3_up = 1; 00087 } 00088 00089 int main() { 00090 xb_led = 0; 00091 xr_led = 0; 00092 xg_led = 0; 00093 led_red=0; 00094 led_green=0; 00095 led_blue=0; 00096 00097 sw2_int.mode (PullUp); 00098 00099 sw2_int.fall(&sw2Down); 00100 sw2_int.rise(&sw2Up); 00101 00102 sw3_int.mode (PullUp); 00103 00104 sw3_int.fall(&sw3Down); 00105 sw3_int.rise(&sw3Up); 00106 00107 tempSender.attach(&sendTemp, 2.0); 00108 00109 pc.baud(115200); 00110 pc.printf("%f", lm_temp.read()); 00111 pc.printf(";"); 00112 string buf; 00113 while (true) { 00114 if(sw2_down) { 00115 pc.printf("2d;"); 00116 sw2_down = 0; 00117 } 00118 if(sw2_up) { 00119 pc.printf("2u;"); 00120 sw2_up = 0; 00121 } 00122 if(sw3_down) { 00123 pc.printf("3d;"); 00124 sw3_down = 0; 00125 } 00126 if(sw3_up) { 00127 pc.printf("3u;"); 00128 sw3_up = 0; 00129 } 00130 if(pc.readable()) { 00131 char x = pc.getc(); 00132 if(x==';') { 00133 parse(buf); 00134 buf = ""; 00135 } 00136 else { 00137 buf += x; 00138 } 00139 } 00140 if(temp_flag) { 00141 temp_flag=0; 00142 pc.printf("%f", lm_temp.read()); 00143 pc.printf(";"); 00144 } 00145 } 00146 } 00147
Generated on Wed Jul 13 2022 18:35:03 by
