Stefan Simbürger
/
04_TINF_Interrupt
Interrupt Spielereien
Diff: main.cpp
- Revision:
- 1:c880c990b9b9
- Parent:
- 0:9db80233bfe2
- Child:
- 2:afd73f8f51fe
diff -r 9db80233bfe2 -r c880c990b9b9 main.cpp --- a/main.cpp Mon Dec 02 18:28:02 2019 +0000 +++ b/main.cpp Mon Dec 16 18:22:04 2019 +0000 @@ -1,48 +1,51 @@ #include "mbed.h" - -//Alle Buttons am Joystick definieren -DigitalIn ButtonDown(p12); -DigitalIn ButtonLeft(p13); -DigitalIn ButtonCenter(p14); -DigitalIn ButtonUp(p15); -DigitalIn ButtonRight(p16); +#define BUTTON1 p14 // push joystick pin +#define BUTTONLEFT p13 +#define BUTTONDOWN p12 BusOut myleds(LED1, LED2, LED3, LED4); -void Reset(uint8_t mask); -void bitLeft(); -/* -void print_binary(uint8_t x) { // function to print binary - for(int i=sizeof(x)<<3; i; i--) - putchar('0'+((x>>(i-1))&1)); -}*/ -int main() -{ - uint8_t mask = 0b00001111; +Ticker t1; +Ticker t3; +Timeout t2; +InterruptIn btn(BUTTON1); +InterruptIn btnLeft(BUTTONLEFT); +InterruptIn btnDown(BUTTONDOWN); + +uint8_t bitMask = 0x00; - //bool lastButtonstate; - while(1) - { - if(ButtonCenter) - { - Reset(mask); - } - if(ButtonLeft) - { - bitLeft(); - } - } +void blink_led4() { + + myleds = myleds ^ 0x08; +} + +void toggle_led1() { + + myleds = 0x01; +} + +void turn_all_Led_on() { + + myleds = myleds | 0x0F; + t1.detach(); } -void Reset(uint8_t mask) -{ - myleds = mask; +void leds_off(){ + + myleds = myleds & bitMask; + t1.attach(callback(&blink_led4), 1.0f); } -void bitLeft() -{ - +void ledsLeft(){ + myleds = myleds << 1; - wait_ms(500); - -} \ No newline at end of file +} +int main() { + + t1.attach(callback(&blink_led4), 1.0f); + t3.attach(callback(&leds_off), 15.0f); + btn.fall(callback(&toggle_led1)); + btnLeft.fall(callback(&ledsLeft)); + btnDown.fall(callback(&turn_all_Led_on)); + +}