Mirza Mesic
/
tinf_interrupt
ver1
main.cpp@0:6bec68b237c8, 2019-12-16 (annotated)
- Committer:
- mirzamesic
- Date:
- Mon Dec 16 18:29:12 2019 +0000
- Revision:
- 0:6bec68b237c8
Interrupt aufgabe
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mirzamesic | 0:6bec68b237c8 | 1 | #include "mbed.h" |
mirzamesic | 0:6bec68b237c8 | 2 | #define BUTTON1 p14 // push joystick pin |
mirzamesic | 0:6bec68b237c8 | 3 | #define BUTTON2 p12 // push joystick pin down |
mirzamesic | 0:6bec68b237c8 | 4 | |
mirzamesic | 0:6bec68b237c8 | 5 | DigitalOut led1(LED1); |
mirzamesic | 0:6bec68b237c8 | 6 | DigitalOut led2(LED2); |
mirzamesic | 0:6bec68b237c8 | 7 | |
mirzamesic | 0:6bec68b237c8 | 8 | |
mirzamesic | 0:6bec68b237c8 | 9 | InterruptIn button(BUTTON1); |
mirzamesic | 0:6bec68b237c8 | 10 | InterruptIn button1(BUTTON2); |
mirzamesic | 0:6bec68b237c8 | 11 | |
mirzamesic | 0:6bec68b237c8 | 12 | Ticker t1; |
mirzamesic | 0:6bec68b237c8 | 13 | float zeit = 0.2; |
mirzamesic | 0:6bec68b237c8 | 14 | uint8_t counter = 0; |
mirzamesic | 0:6bec68b237c8 | 15 | |
mirzamesic | 0:6bec68b237c8 | 16 | |
mirzamesic | 0:6bec68b237c8 | 17 | void blink_led1() |
mirzamesic | 0:6bec68b237c8 | 18 | { |
mirzamesic | 0:6bec68b237c8 | 19 | led1 = !led1; |
mirzamesic | 0:6bec68b237c8 | 20 | } |
mirzamesic | 0:6bec68b237c8 | 21 | |
mirzamesic | 0:6bec68b237c8 | 22 | void toggle() |
mirzamesic | 0:6bec68b237c8 | 23 | { |
mirzamesic | 0:6bec68b237c8 | 24 | zeit=0.1; |
mirzamesic | 0:6bec68b237c8 | 25 | } |
mirzamesic | 0:6bec68b237c8 | 26 | void toggle1() |
mirzamesic | 0:6bec68b237c8 | 27 | { |
mirzamesic | 0:6bec68b237c8 | 28 | zeit=0.2; |
mirzamesic | 0:6bec68b237c8 | 29 | } |
mirzamesic | 0:6bec68b237c8 | 30 | |
mirzamesic | 0:6bec68b237c8 | 31 | void druckanzahl(){ |
mirzamesic | 0:6bec68b237c8 | 32 | |
mirzamesic | 0:6bec68b237c8 | 33 | counter++; |
mirzamesic | 0:6bec68b237c8 | 34 | if(counter==10){ |
mirzamesic | 0:6bec68b237c8 | 35 | led2=1; |
mirzamesic | 0:6bec68b237c8 | 36 | counter=0; |
mirzamesic | 0:6bec68b237c8 | 37 | } |
mirzamesic | 0:6bec68b237c8 | 38 | else |
mirzamesic | 0:6bec68b237c8 | 39 | led2=0; |
mirzamesic | 0:6bec68b237c8 | 40 | } |
mirzamesic | 0:6bec68b237c8 | 41 | |
mirzamesic | 0:6bec68b237c8 | 42 | |
mirzamesic | 0:6bec68b237c8 | 43 | |
mirzamesic | 0:6bec68b237c8 | 44 | |
mirzamesic | 0:6bec68b237c8 | 45 | int main() |
mirzamesic | 0:6bec68b237c8 | 46 | { |
mirzamesic | 0:6bec68b237c8 | 47 | |
mirzamesic | 0:6bec68b237c8 | 48 | button.rise(&toggle); |
mirzamesic | 0:6bec68b237c8 | 49 | button.fall(&toggle1); |
mirzamesic | 0:6bec68b237c8 | 50 | button1.rise(&druckanzahl); |
mirzamesic | 0:6bec68b237c8 | 51 | while(1) { |
mirzamesic | 0:6bec68b237c8 | 52 | |
mirzamesic | 0:6bec68b237c8 | 53 | blink_led1(); |
mirzamesic | 0:6bec68b237c8 | 54 | wait(zeit); |
mirzamesic | 0:6bec68b237c8 | 55 | |
mirzamesic | 0:6bec68b237c8 | 56 | |
mirzamesic | 0:6bec68b237c8 | 57 | } |
mirzamesic | 0:6bec68b237c8 | 58 | } |