Syed Shakeeb Sadiq / Mbed 2 deprecated Genie_mbed_Gecko

Dependencies:   4dGENIE mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "mbed_genie.h"
00003  
00004 Mbed4dGenie genie(PB9, PB10, PB11); 
00005 DigitalOut led1(LED1);
00006 DigitalOut led2(LED2);
00007 
00008 bool winButton0Status = false; //holds the "status" of winButton0 object.
00009 bool winButton1Status = false; //holds the "status" of winButton1 object.
00010 
00011 int userLed0Status = 0; 
00012 int userLed1Status = 0;
00013  
00014 void myGenieEventHandler(void)  //Event handler for the 4d Systems display
00015 {
00016     genieFrame Event;
00017     genie.genieDequeueEvent(&Event);
00018     
00019     //event report from an object
00020     if(Event.reportObject.cmd == GENIE_REPORT_EVENT) 
00021     {        
00022         if (Event.reportObject.object == GENIE_OBJ_WINBUTTON) // If the Reported Message was from a winbutton
00023         { 
00024             if (Event.reportObject.index == 0) 
00025             {
00026                 if (winButton0Status == false) {
00027                     printf("Button 1 pressed\n\r");
00028                     printf("LED 1 is On now\n\r");                    
00029                     led1 = 1;
00030                     userLed0Status = 1;
00031                     winButton0Status = !winButton0Status;
00032                 }
00033                 
00034                  else if (winButton0Status == true) {
00035                     printf("Button 1 pressed\n\r");
00036                     printf("LED 1 is Off now\n\r");                    
00037                     led1 = 0;
00038                     userLed0Status = 0;
00039                     winButton0Status = !winButton0Status;
00040                 }
00041             }
00042                 
00043             if (Event.reportObject.index == 1) 
00044             {             
00045                 if(winButton1Status == false) {
00046                     printf("Button 2 pressed\n\r"); 
00047                     printf("LED 2 is On now\n\r"); 
00048                     led2 = 1;
00049                     userLed1Status = 1;
00050                     winButton1Status = !winButton1Status;
00051                 }
00052 
00053                 else if(winButton1Status == true) {
00054                     printf("Button 2 pressed\n\r"); 
00055                     printf("LED 2 is Off now\n\r"); 
00056                     led2 = 0;
00057                     userLed1Status = 0;
00058                     winButton1Status = !winButton1Status;
00059                 }
00060 
00061             }
00062             
00063         }
00064     }
00065 }
00066  
00067 int main()
00068  
00069 {
00070     genie.Start();
00071     genie.genieAttachEventHandler(&myGenieEventHandler); // Call the event handler 
00072     
00073     printf("Syed's mbed Gecko board Winbutton-LED Demo \n\r");  // Display a welcome message on the serial monitor
00074  
00075     while(1) 
00076     
00077     {                                                  // initialise an infinite while loop
00078     
00079     genie.genieWriteObject(GENIE_OBJ_USER_LED,0,userLed0Status);      // Set the USERLED0 object high if button 0 is pressed
00080     genie.genieWriteObject(GENIE_OBJ_USER_LED,1,userLed1Status);      // Set the USERLED1 object high if button 1 is pressed
00081     
00082     wait(1);                                           // Wait one second      
00083     
00084     }
00085 }