Dependencies:   mbed lwip

main.cpp

Committer:
chris
Date:
2009-09-22
Revision:
1:bde97f4fdef6
Parent:
0:f4582ce9b8d7

File content as of revision 1:bde97f4fdef6:

#include "DemoBoard.h"



// Function for Rising ede of RedButton
void RedRise () { 
    led1 = !led1;
}




int main() {

    // Attach the interupt hander to RedButton
    RedButton.rise(&RedRise);

    // Print to LCD and the serial port
    lcd.printf("Hello World!");
    pc.printf("Hello World!");
    

    while (1) {
    
       
// ----------------------------------
// Accelerometer example 
// ----------------------------------

/*     
        float x = acc.x();
        float y = acc.y();
        float z = acc.z();
        lcd.locate(0,0);
        lcd.printf("x=%0.3f      ",x);
        lcd.locate(0,1);
        lcd.printf("y=%0.3f      ",y);
        lcd.locate(0,2);
        lcd.printf("z=%0.3f      ",z);
        wait (0.5);
*/


// ----------------------------------
// RFID Example
// ----------------------------------
/*
        if (rfid.readable()) {
            int id=rfid.read();
            lcd.cls();
            lcd.printf("ID : %d",id);
            
        }
*/
        
        
// ----------------------------------
// Accelerometer example 
// ----------------------------------

/*     
        float x = acc.x();
        float y = acc.y();
        float z = acc.z();
        lcd.locate(0,0);
        lcd.printf("x=%0.3f      ",x);
        lcd.locate(0,1);
        lcd.printf("y=%0.3f      ",y);
        lcd.locate(0,2);
        lcd.printf("z=%0.3f      ",z);
        wait (0.5);
*/



// ----------------------------------
// Servo example 
// ----------------------------------
/*
        servo=pot;
        wait (0.01);
*/        
        
// ----------------------------------
// RGB LED example with accelerometer
// ----------------------------------
/*
        rgb.red(abs(acc.x()));      
        rgb.green(abs(acc.y()));      
        rgb.blue(abs(acc.z()));      
*/
        
        
// ----------------------------------
// Light sensor example
// ----------------------------------
/*
        lcd.locate(0,0);
        lcd.printf("Light: %.2f ",light.read());
        wait (0.2);                
*/


// ----------------------------------
// USB HID
// ----------------------------------
/*
    if (rfid.readable()) {
        int id;
        char msg[25];
        id = rfid.read();
        sprintf(msg,"Tag ID : %d\n",id);
        hid.keyboard(msg);    
    }

*/



// ----------------------------------
// RPC over ethernet
// ----------------------------------
/*

  // Create a HTTPServer on default Port
  HTTPServer *http = new HTTPServer();
  // Register RPC in /rpc space 
  http->addHandler(new HTTPRPC());
  // HTTP File system  
  http->addHandler(new HTTPFileSystemHandler("/", "/local/"));
  // Register the HTTPServer on the Network device (will hopfully disappear in the next Version)
  http->bind();

  NetServer *net = NetServer::get();
  
  lcd.locate(0,1);
  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);

  while(1) {
      http->poll();
    }

*/




// ----------------------------------
// Ultra Sonic range finder
// ----------------------------------
        float d = srf;
        
        float norm = (2.0/d) - 0.02; // max 1.0, min 0.02
        
        rgb.red(norm);
        rgb.green(1.0-norm);
        pc.printf("%f\n",norm);
        pc.printf("Range is %.1f cm\n",(float)srf);
        wait (0.2);
  
  
    }
   
  
}