00001 #include "DemoBoard.h"00002
00003 /*00004 * This project used and ultrasonic range finder to blend and RGB LED from00005 * green to yellow to red as the ranged object gets closer00006 */00007
00008 int main() {
00009
00010 while (1) {
00011
00012 // Take a reading from the Ultrasonic Range Finder00013 float d = srf;
00014
00015 // Scale and trim the number so it approaches 0.0 at a long range00016 // and approaches 1.0 as the range gets closer00017 float normalised = (2.0/d) - 0.02;
00018
00019 // Set the red component to get brighter the closer the range00020 rgb.red(normalised);
00021
00022 // Set the red component to get brighter the further the range00023 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