Chris Styles / Mbed 2 deprecated DemoBoard_RangeIndicator

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  * This project used and ultrasonic range finder to blend and RGB LED from
00005  * green to yellow to red as the ranged object gets closer
00006  */
00007 
00008 int main() {    
00009 
00010     while (1) {
00011     
00012         // Take a reading from the Ultrasonic Range Finder
00013         float d = srf;
00014         
00015         // Scale and trim the number so it approaches 0.0 at a long range
00016         // and approaches 1.0 as the range gets closer
00017         float normalised = (2.0/d) - 0.02;
00018         
00019         // Set the red component to get brighter the closer the range
00020         rgb.red(normalised);
00021         
00022         // Set the red component to get brighter the further the range
00023         rgb.green(1.0-normalised);
00024 
00025         // For completeness, print the measured range 
00026         pc.printf("Range is %.1f cm\n",(float)srf);
00027         wait (0.2);
00028   
00029     }
00030 
00031 }
00032 
00033