Controlling a Grove LED bar (D5) with a Grove button (A0).

Dependencies:   LED_Bar mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "LED_Bar.h"
00003 
00004 LED_Bar bar(D6, D5);
00005 DigitalIn button(A0);
00006 
00007 int main() {
00008     int j;
00009     bar.setLevel(0);
00010 
00011     while(1) {
00012         wait(0.3);
00013         if (button) {
00014             bar.setLevel(j++);
00015         } else {
00016             bar.setLevel(j);
00017         }
00018         if (j == 11) {
00019             bar.setLevel(0);
00020             j = 0;
00021         }
00022     }
00023 }