Bernd Eisenberger / Mbed 2 deprecated Tinf_002_Bitmanipulation

Dependencies:   mbed DigitalIn

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 #define Button1 p12
00004 #define Button3 p14
00005 #define Button2 p15
00006 
00007 
00008 
00009 BusOut myleds(LED4, LED3, LED2, LED1);
00010 
00011 DigitalIn up(Button1);
00012 DigitalIn down(Button2);
00013 DigitalIn center(Button3);
00014 
00015 int main()
00016 {
00017     while(1) {
00018 
00019 
00020 
00021         if(up.read()==1) {
00022             if(myleds<=14) {
00023                 wait_ms(50);
00024                 myleds=myleds<<1;
00025                 myleds=1|myleds;
00026 
00027             }
00028 
00029             if(myleds>=14) {
00030 
00031                 wait_ms(50);
00032                 myleds=myleds<<1;
00033                 myleds=myleds|0;
00034 
00035             }
00036                 
00037 
00038             
00039 
00040 
00041         }
00042         if(center.read()==1) {
00043             wait_ms(100);
00044             for(int i=0; i<4; i++) {
00045                 wait_ms(100);
00046                 myleds=myleds<<1;
00047                 myleds=myleds|0;
00048             }
00049         }
00050         
00051         
00052         if(down.read()==1) {
00053             if(myleds<=15) {
00054                 wait_ms(50);
00055                 myleds=myleds>>1;
00056                 myleds=0|myleds;
00057 
00058             }
00059 
00060             if(myleds>=15) {
00061 
00062                 wait_ms(50);
00063                 myleds=myleds>>1;
00064                 myleds=myleds|0;
00065 
00066             } 
00067         
00068 
00069 
00070     }
00071 }
00072 }