A demonstration of how to drive the onboard LEDS on the LPC1768 via a 4.3 inch touch-screen display from 4D Systems
main.cpp
00001 /* A quick example program to show 00002 how to use the Mbed LPC1768 with the 00003 4D systems 4.3 inch capacitive touch 00004 screen. 00005 00006 The display has four vitual winButton objects 00007 which when touched change the state of four 00008 virtual led (userLed) objects. The led objects on 00009 change of state send a serial message out to 00010 the Mbed serial port on pins 9 and 10. 00011 00012 This message tells the Mbed to drive 00013 actual corresponding LEDS 00014 1 to 4 appropriately 00015 00016 */ 00017 00018 #include "mbed.h" 00019 #include "mbed_genie.h" 00020 00021 DigitalOut led1(LED1); 00022 DigitalOut led2(LED2); 00023 DigitalOut led3(LED3); 00024 DigitalOut led4(LED4); 00025 00026 bool winButton0Status = false; //holds the "status" of winButton0 object. 00027 bool userLed0Status = false; //hold the "status" of userLed0 object. 00028 00029 bool winButton1Status = false; //holds the "status" of winButton1 object. 00030 bool userLed1Status = false; //hold the "status" of userLed1 object. 00031 00032 bool winButton2Status = false; //holds the "status" of winButton2 object. 00033 bool userLed2Status = false; //hold the "status" of userLed2 object. 00034 00035 bool winButton3Status = false; //holds the "status" of winButton3 object. 00036 bool userLed3Status = false; //hold the "status" of userLed3 object. 00037 00038 00039 //Event handler for the 4d Systems display 00040 void myGenieEventHandler(void) 00041 { 00042 genieFrame Event; 00043 genieDequeueEvent(&Event); 00044 00045 if(Event.reportObject.cmd == GENIE_REPORT_EVENT) { 00046 00047 // If the Reported Message was from winbutton0 and userLed0 is off 00048 00049 if (Event.reportObject.object == GENIE_OBJ_WINBUTTON) { 00050 if ((Event.reportObject.index == 0) && (userLed0Status==false)) { 00051 printf("LED1 High \r\n"); 00052 wait(0.1); 00053 winButton0Status=true; 00054 } 00055 } 00056 00057 // If the Reported Message was from winbutton0 and userLed0 is on 00058 00059 if (Event.reportObject.object == GENIE_OBJ_WINBUTTON) { 00060 if ((Event.reportObject.index == 0) && (userLed0Status == true)) { 00061 printf("LED1 Low \r\n"); 00062 wait(0.1); 00063 winButton0Status=false; 00064 } 00065 } 00066 00067 // If the Reported Message was from winbutton1 and userLed1 is off 00068 00069 if (Event.reportObject.object == GENIE_OBJ_WINBUTTON) { 00070 if ((Event.reportObject.index == 1) && (userLed1Status==false)) { 00071 printf("LED2 High \r\n"); 00072 wait(0.1); 00073 winButton1Status=true; 00074 } 00075 } 00076 00077 // If the Reported Message was from winbutton1 and userLed1 is on 00078 00079 if (Event.reportObject.object == GENIE_OBJ_WINBUTTON) { 00080 if ((Event.reportObject.index == 1) && (userLed1Status == true)) { 00081 printf("LED2 Low \r\n"); 00082 wait(0.1); 00083 winButton1Status=false; 00084 } 00085 } 00086 00087 // If the Reported Message was from winbutton2 and userLed2 is off 00088 00089 if (Event.reportObject.object == GENIE_OBJ_WINBUTTON) { 00090 if ((Event.reportObject.index == 2) && (userLed2Status==false)) { 00091 printf("LED High \r\n"); 00092 wait(0.1); 00093 winButton2Status=true; 00094 } 00095 } 00096 00097 // If the Reported Message was from winbutton2 and userLed2 is on 00098 00099 if (Event.reportObject.object == GENIE_OBJ_WINBUTTON) { 00100 if ((Event.reportObject.index == 2) && (userLed2Status == true)) { 00101 printf("LED Low \r\n"); 00102 wait(0.1); 00103 winButton2Status=false; 00104 } 00105 } 00106 00107 // If the Reported Message was from winbutton3 and userLed3 is off 00108 00109 if (Event.reportObject.object == GENIE_OBJ_WINBUTTON) { 00110 if ((Event.reportObject.index == 3) && (userLed3Status==false)) { 00111 printf("LED High \r\n"); 00112 wait(0.1); 00113 winButton3Status=true; 00114 } 00115 } 00116 00117 // If the Reported Message was from winbutton3 and userLed3 is on 00118 00119 if (Event.reportObject.object == GENIE_OBJ_WINBUTTON) { 00120 if ((Event.reportObject.index == 3) && (userLed3Status == true)) { 00121 printf("LED Low \r\n"); 00122 wait(0.1); 00123 winButton3Status=false; 00124 } 00125 } 00126 } 00127 } 00128 00129 00130 int main() 00131 { 00132 00133 SetupGenie(); 00134 00135 genieAttachEventHandler(&myGenieEventHandler); 00136 00137 printf("Langsters's mbed Visi-Genie LED demo \r\n"); 00138 00139 genieWriteContrast(15); //set screen contrast to full brightness 00140 00141 while(1) { 00142 00143 //check if winButton0 is High & set LED0 High 00144 00145 if (winButton0Status == true) { 00146 printf("Button 0 in On State! \r\n"); //send button status message 00147 genieWriteObject(GENIE_OBJ_USER_LED, 0x00, 1); // set virtual LED0 High 00148 wait(0.1); // wait 100uS 00149 led1 = 1; // set actual LED1 High 00150 userLed0Status = true; // set userLed0Status High 00151 00152 } 00153 00154 //check if winButton0 is low & set LED low 00155 00156 else if (winButton0Status == false) { 00157 printf("Button 0 in Off state! \r\n"); //send button status message 00158 genieWriteObject(GENIE_OBJ_USER_LED, 0x00, 0); // set virtual LED0 Low 00159 wait(0.1); // wait 100uS 00160 led1 = 0; // set actual LED1 Low 00161 userLed0Status = false; //set userLed0Status Low 00162 00163 } 00164 00165 //check if winButton1 is High & set LED High 00166 00167 if (winButton1Status == true) { 00168 printf("Button 1 in On State! \r\n"); //send button status message 00169 genieWriteObject(GENIE_OBJ_USER_LED, 0x01, 1); // set virtual LED0 High 00170 wait(0.1); // wait 100uS 00171 led2 = 1; // set actual LED2 High 00172 userLed1Status = true; // set userLed1Status High 00173 00174 } 00175 00176 //check if winButton1 is low & set LED low 00177 00178 else if (winButton1Status == false) { 00179 printf("Button 1 in Off state! \r\n"); //send button status message 00180 genieWriteObject(GENIE_OBJ_USER_LED, 0x01, 0); // set virtual LED0 Low 00181 wait(0.1); // wait 100uS 00182 led2 = 0; // set actual LED1 Low 00183 userLed1Status = false; //set userLed1Status Low 00184 00185 } 00186 00187 //check if winButton2 is High & set LED High 00188 00189 if (winButton2Status == true) { 00190 printf("Button 2 in On State! \r\n"); //send button status message 00191 genieWriteObject(GENIE_OBJ_USER_LED, 0x02, 1); // set virtual LED0 High 00192 wait(0.1); // wait 100uS 00193 led3 = 1; // set actual LED2 High 00194 userLed2Status = true; // set userLed1Status High 00195 00196 } 00197 00198 //check if winButton2 is low & set LED low 00199 00200 else if (winButton2Status == false) { 00201 printf("Button 2 in Off state! \r\n"); //send button status message 00202 genieWriteObject(GENIE_OBJ_USER_LED, 0x02, 0); // set virtual LED0 Low 00203 wait(0.1); // wait 100uS 00204 led3 = 0; // set actual LED1 Low 00205 userLed2Status = false; //set userLed1Status Low 00206 00207 } 00208 00209 //check if winButton3 is High & set LED High 00210 00211 if (winButton3Status == true) { 00212 printf("Button 3 in On State! \r\n"); //send button status message 00213 genieWriteObject(GENIE_OBJ_USER_LED, 0x03, 1); // set virtual LED0 High 00214 wait(0.1); // wait 100uS 00215 led4 = 1; // set actual LED2 High 00216 userLed3Status = true; // set userLed1Status High 00217 00218 } 00219 00220 //check if winButton2 is low & set LED low 00221 00222 else if (winButton3Status == false) { 00223 printf("Button 3 in Off state! \r\n"); //send button status message 00224 genieWriteObject(GENIE_OBJ_USER_LED, 0x03, 0); // set virtual LED0 Low 00225 wait(0.1); // wait 100uS 00226 led4 = 0; // set actual LED1 Low 00227 userLed3Status = false; //set userLed1Status Low 00228 00229 } 00230 00231 00232 } 00233 00234 }
Generated on Tue Jul 12 2022 22:46:18 by 1.7.2