Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
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
Generated on Fri Jul 15 2022 14:29:03 by
1.7.2