Chris Styles / Mbed 2 deprecated DemoBoard_RFID_HID

Dependencies:   mbed lwip

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "DemoBoard.h"
00002 
00003 
00004 
00005 // Function for Rising ede of RedButton
00006 void RedRise () { 
00007     led1 = !led1;
00008 }
00009 
00010 
00011 
00012 
00013 int main() {
00014 
00015     // Attach the interupt hander to RedButton
00016     RedButton.rise(&RedRise);
00017 
00018     // Print to LCD and the serial port
00019     lcd.printf("Hello World!");
00020     pc.printf("Hello World!");
00021     
00022 
00023     while (1) {
00024     
00025        
00026 // ----------------------------------
00027 // Accelerometer example 
00028 // ----------------------------------
00029 
00030 /*     
00031         float x = acc.x();
00032         float y = acc.y();
00033         float z = acc.z();
00034         lcd.locate(0,0);
00035         lcd.printf("x=%0.3f      ",x);
00036         lcd.locate(0,1);
00037         lcd.printf("y=%0.3f      ",y);
00038         lcd.locate(0,2);
00039         lcd.printf("z=%0.3f      ",z);
00040         wait (0.5);
00041 */
00042 
00043 
00044 // ----------------------------------
00045 // RFID Example
00046 // ----------------------------------
00047 /*
00048         if (rfid.readable()) {
00049             int id=rfid.read();
00050             lcd.cls();
00051             lcd.printf("ID : %d",id);
00052             
00053         }
00054 */
00055         
00056         
00057 // ----------------------------------
00058 // Accelerometer example 
00059 // ----------------------------------
00060 
00061 /*     
00062         float x = acc.x();
00063         float y = acc.y();
00064         float z = acc.z();
00065         lcd.locate(0,0);
00066         lcd.printf("x=%0.3f      ",x);
00067         lcd.locate(0,1);
00068         lcd.printf("y=%0.3f      ",y);
00069         lcd.locate(0,2);
00070         lcd.printf("z=%0.3f      ",z);
00071         wait (0.5);
00072 */
00073 
00074 
00075 
00076 // ----------------------------------
00077 // Servo example 
00078 // ----------------------------------
00079 /*
00080         servo=pot;
00081         wait (0.01);
00082 */        
00083         
00084 // ----------------------------------
00085 // RGB LED example with accelerometer
00086 // ----------------------------------
00087 /*
00088         rgb.red(abs(acc.x()));      
00089         rgb.green(abs(acc.y()));      
00090         rgb.blue(abs(acc.z()));      
00091 */
00092         
00093         
00094 // ----------------------------------
00095 // Light sensor example
00096 // ----------------------------------
00097 /*
00098         lcd.locate(0,0);
00099         lcd.printf("Light: %.2f ",light.read());
00100         wait (0.2);                
00101 */
00102 
00103 
00104 // ----------------------------------
00105 // USB HID
00106 // ----------------------------------
00107 /*
00108     if (rfid.readable()) {
00109         int id;
00110         char msg[25];
00111         id = rfid.read();
00112         sprintf(msg,"Tag ID : %d\n",id);
00113         hid.keyboard(msg);    
00114     }
00115 
00116 */
00117 
00118 
00119 
00120 // ----------------------------------
00121 // RPC over ethernet
00122 // ----------------------------------
00123 /*
00124 
00125   // Create a HTTPServer on default Port
00126   HTTPServer *http = new HTTPServer();
00127   // Register RPC in /rpc space 
00128   http->addHandler(new HTTPRPC());
00129   // HTTP File system  
00130   http->addHandler(new HTTPFileSystemHandler("/", "/local/"));
00131   // Register the HTTPServer on the Network device (will hopfully disappear in the next Version)
00132   http->bind();
00133 
00134   NetServer *net = NetServer::get();
00135   
00136   lcd.locate(0,1);
00137   lcd.printf("%hhu.%hhu.%hhu.%hhu", (net->getIPAddr().addr)&0xFF, (net->getIPAddr().addr>>8)&0xFF, (net->getIPAddr().addr>>16)&0xFF, (net->getIPAddr().addr>>24)&0xFF);
00138 
00139   while(1) {
00140       http->poll();
00141     }
00142 
00143 */
00144 
00145 
00146 
00147 
00148 // ----------------------------------
00149 // Ultra Sonic range finder
00150 // ----------------------------------
00151         float d = srf;
00152         
00153         float norm = (2.0/d) - 0.02; // max 1.0, min 0.02
00154         
00155         rgb.red(norm);
00156         rgb.green(1.0-norm);
00157         pc.printf("%f\n",norm);
00158         pc.printf("Range is %.1f cm\n",(float)srf);
00159         wait (0.2);
00160   
00161   
00162     }
00163    
00164   
00165 }
00166 
00167