Dependencies:   mbed lwip

Committer:
chris
Date:
Sat Sep 19 00:14:43 2009 +0000
Revision:
0:c88750da21d0
Child:
1:7354a0bac81a

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chris 0:c88750da21d0 1 #include "Objects.h"
chris 0:c88750da21d0 2
chris 0:c88750da21d0 3 /*
chris 0:c88750da21d0 4 * This project used and ultrasonic range finder to blend and RGB LED from
chris 0:c88750da21d0 5 * green to yellow to red as the ranged object gets closer
chris 0:c88750da21d0 6 */
chris 0:c88750da21d0 7
chris 0:c88750da21d0 8 int main() {
chris 0:c88750da21d0 9
chris 0:c88750da21d0 10 while (1) {
chris 0:c88750da21d0 11
chris 0:c88750da21d0 12 // Take a reading from the Ultrasonic Range Finder
chris 0:c88750da21d0 13 float d = srf;
chris 0:c88750da21d0 14
chris 0:c88750da21d0 15 // Scale and trim the number so it approaches 0.0 at a long range
chris 0:c88750da21d0 16 // and approaches 1.0 as the range gets closer
chris 0:c88750da21d0 17 float normalised = (2.0/d) - 0.02;
chris 0:c88750da21d0 18
chris 0:c88750da21d0 19 // Set the red component to get brighter the closer the range
chris 0:c88750da21d0 20 rgb.red(norm);
chris 0:c88750da21d0 21
chris 0:c88750da21d0 22 // Set the red component to get brighter the further the range
chris 0:c88750da21d0 23 rgb.green(1.0-norm);
chris 0:c88750da21d0 24
chris 0:c88750da21d0 25 // For completeness, print the measured range
chris 0:c88750da21d0 26 pc.printf("Range is %.1f cm\n",(float)srf);
chris 0:c88750da21d0 27 wait (0.2);
chris 0:c88750da21d0 28
chris 0:c88750da21d0 29 }
chris 0:c88750da21d0 30
chris 0:c88750da21d0 31 }
chris 0:c88750da21d0 32
chris 0:c88750da21d0 33