Bitmanipulation mit Stick

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #define btn1 p14     // push joystick pin
00003 #define btn2 p12    //  joystick down
00004  
00005 BusOut leds(LED1,LED2,LED3,LED4);
00006 
00007 Timer t1; 
00008 Ticker tick1, tick2;
00009 Timeout tout;
00010 InterruptIn btn_push(btn1);
00011 InterruptIn btn_down(btn2);
00012  
00013 void blink_led1() 
00014 {
00015     leds = leds^0b0001;        
00016 }
00017  
00018 void shiftled() 
00019 {       
00020     leds = leds << 1;
00021     leds = leds | 0b0010; 
00022     if ( leds == 0b1111)
00023     {
00024         leds = leds ^ 0b1111;
00025     }
00026 }
00027  
00028 void turn_led2_on() 
00029 {
00030     leds = 0b0010;
00031 }
00032 
00033 void ledsoff()
00034 {
00035     leds = 0b0000;
00036 }
00037  
00038 int main() 
00039 {
00040     //t1.start();
00041     
00042     tick1.attach(callback(&blink_led1), 1.0f);
00043     tick2.attach(callback(&ledsoff), 10.0f);
00044     
00045     btn_push.rise(callback(&turn_led2_on));
00046     btn_down.rise(callback(&shiftled));
00047     //btn.fall(callback(&toggle_led2));
00048  
00049 }