A simple Larsen scanner using the onboard LEDs.... because there aren't enough of these already.

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 BusOut ledarray(LED1, LED2, LED3, LED4);
00004 
00005 int main(void) {
00006     //A flag to indicate which direction we should rotate
00007     bool flag = 0;
00008     //the states of the outputs
00009     char outstates = 1;
00010 
00011     //Place the outputs in a known state
00012     ledarray=1;
00013     
00014     //Infinite loop
00015     while(1) {
00016         wait(0.25);
00017         if (!flag) {
00018             outstates *= 2;
00019             if ((outstates>>3)&&1) flag=1;
00020         } else {
00021             outstates /=2;
00022             if (outstates==1) flag=0;
00023         }
00024         ledarray=outstates;
00025     }
00026 }
00027         
00028