Interrupt Spielereien

Dependencies:   mbed

Committer:
Ursukar
Date:
Mon Dec 16 18:22:04 2019 +0000
Revision:
1:c880c990b9b9
Parent:
0:9db80233bfe2
Child:
2:afd73f8f51fe
Interrupt Spielereien

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Ursukar 0:9db80233bfe2 1 #include "mbed.h"
Ursukar 1:c880c990b9b9 2 #define BUTTON1 p14 // push joystick pin
Ursukar 1:c880c990b9b9 3 #define BUTTONLEFT p13
Ursukar 1:c880c990b9b9 4 #define BUTTONDOWN p12
Ursukar 0:9db80233bfe2 5
Ursukar 0:9db80233bfe2 6 BusOut myleds(LED1, LED2, LED3, LED4);
Ursukar 0:9db80233bfe2 7
Ursukar 1:c880c990b9b9 8 Ticker t1;
Ursukar 1:c880c990b9b9 9 Ticker t3;
Ursukar 1:c880c990b9b9 10 Timeout t2;
Ursukar 1:c880c990b9b9 11 InterruptIn btn(BUTTON1);
Ursukar 1:c880c990b9b9 12 InterruptIn btnLeft(BUTTONLEFT);
Ursukar 1:c880c990b9b9 13 InterruptIn btnDown(BUTTONDOWN);
Ursukar 1:c880c990b9b9 14
Ursukar 1:c880c990b9b9 15 uint8_t bitMask = 0x00;
Ursukar 0:9db80233bfe2 16
Ursukar 1:c880c990b9b9 17 void blink_led4() {
Ursukar 1:c880c990b9b9 18
Ursukar 1:c880c990b9b9 19 myleds = myleds ^ 0x08;
Ursukar 1:c880c990b9b9 20 }
Ursukar 1:c880c990b9b9 21
Ursukar 1:c880c990b9b9 22 void toggle_led1() {
Ursukar 1:c880c990b9b9 23
Ursukar 1:c880c990b9b9 24 myleds = 0x01;
Ursukar 1:c880c990b9b9 25 }
Ursukar 1:c880c990b9b9 26
Ursukar 1:c880c990b9b9 27 void turn_all_Led_on() {
Ursukar 1:c880c990b9b9 28
Ursukar 1:c880c990b9b9 29 myleds = myleds | 0x0F;
Ursukar 1:c880c990b9b9 30 t1.detach();
Ursukar 0:9db80233bfe2 31 }
Ursukar 0:9db80233bfe2 32
Ursukar 1:c880c990b9b9 33 void leds_off(){
Ursukar 1:c880c990b9b9 34
Ursukar 1:c880c990b9b9 35 myleds = myleds & bitMask;
Ursukar 1:c880c990b9b9 36 t1.attach(callback(&blink_led4), 1.0f);
Ursukar 0:9db80233bfe2 37 }
Ursukar 0:9db80233bfe2 38
Ursukar 1:c880c990b9b9 39 void ledsLeft(){
Ursukar 1:c880c990b9b9 40
Ursukar 0:9db80233bfe2 41 myleds = myleds << 1;
Ursukar 1:c880c990b9b9 42 }
Ursukar 1:c880c990b9b9 43 int main() {
Ursukar 1:c880c990b9b9 44
Ursukar 1:c880c990b9b9 45 t1.attach(callback(&blink_led4), 1.0f);
Ursukar 1:c880c990b9b9 46 t3.attach(callback(&leds_off), 15.0f);
Ursukar 1:c880c990b9b9 47 btn.fall(callback(&toggle_led1));
Ursukar 1:c880c990b9b9 48 btnLeft.fall(callback(&ledsLeft));
Ursukar 1:c880c990b9b9 49 btnDown.fall(callback(&turn_all_Led_on));
Ursukar 1:c880c990b9b9 50
Ursukar 1:c880c990b9b9 51 }