Ian Phillips / Mbed 2 deprecated BinaryCounter
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*********************************/
00002 /* Binary Count on the Four LEDs */
00003 /* With optional Trace to TTY    */
00004 /*********************************/
00005 
00006 #include "mbed.h"
00007 
00008 Serial pc(USBTX, USBRX); // tx, rx
00009 DigitalOut led1(LED1), led2(LED2), led3(LED3), led4(LED4);
00010 int p=0, q=0, r=0, s=0;
00011 
00012 
00013 int main() {
00014     led1=0,led2=0,led3=0,led4=0;
00015     pc.printf("\n\nStart ... %d %d %d %d %s \n", p, q, r, s, "Count");
00016 
00017     for (int j=0; j<256; j++) {
00018         //wait(0.2); //Slow it down to see it
00019         if (led1==1&&led2==1&&led3==1) {
00020             led1=0;
00021             led2=0;
00022             led3=0;
00023             led4=!led4;
00024         } else if (led1==1&&led2==1) {
00025             led1=0;
00026             led2=0;
00027             led3=!led3;
00028         } else if (led1==1) {
00029             led1=0;
00030             led2=!led2;
00031         } else led1=!led1;
00032         //pc.printf("Now   ... %d %d %d %d %d \n", p=led1, q=led2, r=led3, s=led4, j); //turn on TTY Trace (slow)
00033     }
00034 }
00035