iDNA Studio
/
nRF52840-Preview-DK-blinky
pull
Fork of nRF52840-Preview-DK-blinky by
main.cpp@2:26e1d1bf3d08, 2017-02-07 (annotated)
- Committer:
- idna
- Date:
- Tue Feb 07 08:21:24 2017 +0000
- Revision:
- 2:26e1d1bf3d08
- Parent:
- 0:54f4263790ee
Testing blinky;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
szqt | 0:54f4263790ee | 1 | #include "mbed.h" |
szqt | 0:54f4263790ee | 2 | |
szqt | 0:54f4263790ee | 3 | //DigitalOut led1(LED1); |
idna | 2:26e1d1bf3d08 | 4 | DigitalOut led1(P0_13);// nRF52840 io |
szqt | 0:54f4263790ee | 5 | DigitalOut led2(P0_14); |
szqt | 0:54f4263790ee | 6 | DigitalOut led3(P0_15); |
szqt | 0:54f4263790ee | 7 | DigitalOut led4(P0_16); |
szqt | 0:54f4263790ee | 8 | |
idna | 2:26e1d1bf3d08 | 9 | InterruptIn button1(P0_11);//(USER_BUTTON nRf52840); |
szqt | 0:54f4263790ee | 10 | InterruptIn button2(P0_12); |
szqt | 0:54f4263790ee | 11 | InterruptIn button3(P0_24); |
szqt | 0:54f4263790ee | 12 | InterruptIn button4(P0_25); |
idna | 2:26e1d1bf3d08 | 13 | int button3_flag=0; |
szqt | 0:54f4263790ee | 14 | |
szqt | 0:54f4263790ee | 15 | void button1_pressed() |
szqt | 0:54f4263790ee | 16 | { |
idna | 2:26e1d1bf3d08 | 17 | led1 = 0; |
szqt | 0:54f4263790ee | 18 | } |
szqt | 0:54f4263790ee | 19 | |
szqt | 0:54f4263790ee | 20 | void button1_released() |
szqt | 0:54f4263790ee | 21 | { |
idna | 2:26e1d1bf3d08 | 22 | led1 = led2 =led3 =led4 = 1;// LED OFF |
idna | 2:26e1d1bf3d08 | 23 | //led1 = 0; |
szqt | 0:54f4263790ee | 24 | } |
szqt | 0:54f4263790ee | 25 | |
szqt | 0:54f4263790ee | 26 | void button2_pressed() |
szqt | 0:54f4263790ee | 27 | { |
idna | 2:26e1d1bf3d08 | 28 | led2 = 0; |
idna | 2:26e1d1bf3d08 | 29 | |
szqt | 0:54f4263790ee | 30 | } |
szqt | 0:54f4263790ee | 31 | |
szqt | 0:54f4263790ee | 32 | void button2_released() |
szqt | 0:54f4263790ee | 33 | { |
idna | 2:26e1d1bf3d08 | 34 | led1 = led2 =led3 =led4 = 1; |
idna | 2:26e1d1bf3d08 | 35 | //led1 = 0; |
szqt | 0:54f4263790ee | 36 | } |
szqt | 0:54f4263790ee | 37 | |
szqt | 0:54f4263790ee | 38 | void button3_pressed() |
szqt | 0:54f4263790ee | 39 | { |
idna | 2:26e1d1bf3d08 | 40 | button3_flag = 1; |
idna | 2:26e1d1bf3d08 | 41 | |
szqt | 0:54f4263790ee | 42 | } |
szqt | 0:54f4263790ee | 43 | |
szqt | 0:54f4263790ee | 44 | void button3_released() |
szqt | 0:54f4263790ee | 45 | { |
idna | 2:26e1d1bf3d08 | 46 | led1 = led2 =led3 =led4 = 1; |
idna | 2:26e1d1bf3d08 | 47 | //led1 = 0; |
idna | 2:26e1d1bf3d08 | 48 | button3_flag=0; |
szqt | 0:54f4263790ee | 49 | } |
szqt | 0:54f4263790ee | 50 | |
szqt | 0:54f4263790ee | 51 | void button4_pressed() |
szqt | 0:54f4263790ee | 52 | { |
idna | 2:26e1d1bf3d08 | 53 | led4 = 0; |
idna | 2:26e1d1bf3d08 | 54 | |
szqt | 0:54f4263790ee | 55 | } |
szqt | 0:54f4263790ee | 56 | |
szqt | 0:54f4263790ee | 57 | void button4_released() |
szqt | 0:54f4263790ee | 58 | { |
idna | 2:26e1d1bf3d08 | 59 | led1 = led2 =led3 =led4 = 1; |
idna | 2:26e1d1bf3d08 | 60 | //led1 = 0; |
szqt | 0:54f4263790ee | 61 | } |
szqt | 0:54f4263790ee | 62 | |
szqt | 0:54f4263790ee | 63 | |
idna | 2:26e1d1bf3d08 | 64 | int main() |
idna | 2:26e1d1bf3d08 | 65 | { |
idna | 2:26e1d1bf3d08 | 66 | led1 = led2 =led3 =led4 = 0; |
szqt | 0:54f4263790ee | 67 | |
szqt | 0:54f4263790ee | 68 | button1.fall(&button1_pressed); |
szqt | 0:54f4263790ee | 69 | button1.rise(&button1_released); |
idna | 2:26e1d1bf3d08 | 70 | |
szqt | 0:54f4263790ee | 71 | button2.fall(&button2_pressed); |
szqt | 0:54f4263790ee | 72 | button2.rise(&button2_released); |
szqt | 0:54f4263790ee | 73 | |
szqt | 0:54f4263790ee | 74 | button3.fall(&button3_pressed); |
szqt | 0:54f4263790ee | 75 | button3.rise(&button3_released); |
szqt | 0:54f4263790ee | 76 | |
szqt | 0:54f4263790ee | 77 | button4.fall(&button4_pressed); |
szqt | 0:54f4263790ee | 78 | button4.rise(&button4_released); |
szqt | 0:54f4263790ee | 79 | |
idna | 2:26e1d1bf3d08 | 80 | |
szqt | 0:54f4263790ee | 81 | while (true) { |
idna | 2:26e1d1bf3d08 | 82 | if(button3_flag == 1) { |
idna | 2:26e1d1bf3d08 | 83 | led3 = 0; |
idna | 2:26e1d1bf3d08 | 84 | wait(0.1); |
idna | 2:26e1d1bf3d08 | 85 | led3 = 1; |
idna | 2:26e1d1bf3d08 | 86 | wait(0.1); |
idna | 2:26e1d1bf3d08 | 87 | } else { |
idna | 2:26e1d1bf3d08 | 88 | |
idna | 2:26e1d1bf3d08 | 89 | |
idna | 2:26e1d1bf3d08 | 90 | led1 = !led1; |
idna | 2:26e1d1bf3d08 | 91 | wait(0.5); |
idna | 2:26e1d1bf3d08 | 92 | led2 = !led2; |
idna | 2:26e1d1bf3d08 | 93 | wait(0.5); |
idna | 2:26e1d1bf3d08 | 94 | led3 = !led3; |
idna | 2:26e1d1bf3d08 | 95 | wait(0.5); |
idna | 2:26e1d1bf3d08 | 96 | led4 = !led4; |
idna | 2:26e1d1bf3d08 | 97 | wait(0.5); |
idna | 2:26e1d1bf3d08 | 98 | } |
szqt | 0:54f4263790ee | 99 | } |
szqt | 0:54f4263790ee | 100 | } |
szqt | 0:54f4263790ee | 101 |