Tina Dokic
/
Uebungen_T_D
LEDs blinken von LED1-LED4,und fangen an von momentane Position an. l
main.cpp@0:72b3da7b1d49, 2020-01-12 (annotated)
- Committer:
- tina_dokic
- Date:
- Sun Jan 12 19:59:58 2020 +0000
- Revision:
- 0:72b3da7b1d49
BitManipulation
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tina_dokic | 0:72b3da7b1d49 | 1 | #include "mbed.h" |
tina_dokic | 0:72b3da7b1d49 | 2 | |
tina_dokic | 0:72b3da7b1d49 | 3 | DigitalOut led1(LED1); |
tina_dokic | 0:72b3da7b1d49 | 4 | DigitalOut led2(LED2); |
tina_dokic | 0:72b3da7b1d49 | 5 | DigitalOut led3(LED3); |
tina_dokic | 0:72b3da7b1d49 | 6 | DigitalOut led4(LED4); |
tina_dokic | 0:72b3da7b1d49 | 7 | |
tina_dokic | 0:72b3da7b1d49 | 8 | uint8_t pos = 0; |
tina_dokic | 0:72b3da7b1d49 | 9 | uint8_t shift = 0; // change the value between 0 and 3 |
tina_dokic | 0:72b3da7b1d49 | 10 | |
tina_dokic | 0:72b3da7b1d49 | 11 | int main() { |
tina_dokic | 0:72b3da7b1d49 | 12 | while (1) { |
tina_dokic | 0:72b3da7b1d49 | 13 | pos = (1 << shift); // shift left |
tina_dokic | 0:72b3da7b1d49 | 14 | if(pos == 0b00001000) |
tina_dokic | 0:72b3da7b1d49 | 15 | { led4 = 1; |
tina_dokic | 0:72b3da7b1d49 | 16 | wait_ms(100); |
tina_dokic | 0:72b3da7b1d49 | 17 | led4=0; |
tina_dokic | 0:72b3da7b1d49 | 18 | led1=1; |
tina_dokic | 0:72b3da7b1d49 | 19 | wait(0.1); |
tina_dokic | 0:72b3da7b1d49 | 20 | led1=0; |
tina_dokic | 0:72b3da7b1d49 | 21 | led2 = 1; |
tina_dokic | 0:72b3da7b1d49 | 22 | wait_ms(100); |
tina_dokic | 0:72b3da7b1d49 | 23 | led2=0; |
tina_dokic | 0:72b3da7b1d49 | 24 | led3 = 1; |
tina_dokic | 0:72b3da7b1d49 | 25 | wait_ms(100); |
tina_dokic | 0:72b3da7b1d49 | 26 | led3=0; |
tina_dokic | 0:72b3da7b1d49 | 27 | } |
tina_dokic | 0:72b3da7b1d49 | 28 | if(pos == 0b00000100) |
tina_dokic | 0:72b3da7b1d49 | 29 | { led3 = 1; |
tina_dokic | 0:72b3da7b1d49 | 30 | wait_ms(100); |
tina_dokic | 0:72b3da7b1d49 | 31 | led3=0; |
tina_dokic | 0:72b3da7b1d49 | 32 | led4=1; |
tina_dokic | 0:72b3da7b1d49 | 33 | wait(0.1); |
tina_dokic | 0:72b3da7b1d49 | 34 | led4=0; |
tina_dokic | 0:72b3da7b1d49 | 35 | led1 = 1; |
tina_dokic | 0:72b3da7b1d49 | 36 | wait_ms(100); |
tina_dokic | 0:72b3da7b1d49 | 37 | led1=0; |
tina_dokic | 0:72b3da7b1d49 | 38 | led2= 1; |
tina_dokic | 0:72b3da7b1d49 | 39 | wait_ms(100); |
tina_dokic | 0:72b3da7b1d49 | 40 | led2=0; |
tina_dokic | 0:72b3da7b1d49 | 41 | } |
tina_dokic | 0:72b3da7b1d49 | 42 | if(pos == 0b00000001) |
tina_dokic | 0:72b3da7b1d49 | 43 | { led1 = 1; |
tina_dokic | 0:72b3da7b1d49 | 44 | wait_ms(400); |
tina_dokic | 0:72b3da7b1d49 | 45 | led1=0; |
tina_dokic | 0:72b3da7b1d49 | 46 | led2=1; |
tina_dokic | 0:72b3da7b1d49 | 47 | wait(0.4); |
tina_dokic | 0:72b3da7b1d49 | 48 | led2=0; |
tina_dokic | 0:72b3da7b1d49 | 49 | led3 = 1; |
tina_dokic | 0:72b3da7b1d49 | 50 | wait_ms(400); |
tina_dokic | 0:72b3da7b1d49 | 51 | led3=0; |
tina_dokic | 0:72b3da7b1d49 | 52 | led4 = 1; |
tina_dokic | 0:72b3da7b1d49 | 53 | wait_ms(400); |
tina_dokic | 0:72b3da7b1d49 | 54 | led4=0; |
tina_dokic | 0:72b3da7b1d49 | 55 | } |
tina_dokic | 0:72b3da7b1d49 | 56 | } |
tina_dokic | 0:72b3da7b1d49 | 57 | } |