Simple example using the mbed libraries to target the MCB1700

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 BusOut leds(P1_28, P1_29, P1_31, P2_2, P2_3, P2_4, P2_5, P2_6);
00004 AnalogIn in(P0_25);
00005 
00006 int main() {
00007     while (true) {
00008         float value = 8.0 * in.read();
00009         printf("analog in: %f\n\r", value);
00010 
00011         int led_mask = 0;
00012         if (value > 0.5) led_mask |= 1 << 0;
00013         if (value > 1.5) led_mask |= 1 << 1;
00014         if (value > 2.5) led_mask |= 1 << 2;
00015         if (value > 3.5) led_mask |= 1 << 3;
00016         if (value > 4.5) led_mask |= 1 << 4;
00017         if (value > 5.5) led_mask |= 1 << 5;
00018         if (value > 6.5) led_mask |= 1 << 6;
00019         if (value > 7.5) led_mask |= 1 << 7;
00020         leds = led_mask;
00021 
00022         wait(1);
00023     }
00024 }