iDNA Studio
/
nRF52840-Preview-DK-blinky
pull
Fork of nRF52840-Preview-DK-blinky by
main.cpp@0:54f4263790ee, 2017-02-06 (annotated)
- Committer:
- szqt
- Date:
- Mon Feb 06 11:03:48 2017 +0000
- Revision:
- 0:54f4263790ee
- Child:
- 2:26e1d1bf3d08
nRF52840 Preview DK led and button test
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); |
szqt | 0:54f4263790ee | 4 | DigitalOut led1(P0_13); |
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 | |
szqt | 0:54f4263790ee | 9 | |
szqt | 0:54f4263790ee | 10 | InterruptIn button1(P0_11);//(USER_BUTTON); |
szqt | 0:54f4263790ee | 11 | InterruptIn button2(P0_12); |
szqt | 0:54f4263790ee | 12 | InterruptIn button3(P0_24); |
szqt | 0:54f4263790ee | 13 | InterruptIn button4(P0_25); |
szqt | 0:54f4263790ee | 14 | |
szqt | 0:54f4263790ee | 15 | void button1_pressed() |
szqt | 0:54f4263790ee | 16 | { |
szqt | 0:54f4263790ee | 17 | led1 = led2 =led3 =led4 = 1; |
szqt | 0:54f4263790ee | 18 | led1 = 0; |
szqt | 0:54f4263790ee | 19 | |
szqt | 0:54f4263790ee | 20 | } |
szqt | 0:54f4263790ee | 21 | |
szqt | 0:54f4263790ee | 22 | void button1_released() |
szqt | 0:54f4263790ee | 23 | { |
szqt | 0:54f4263790ee | 24 | led1 = led2 =led3 =led4 = 1; |
szqt | 0:54f4263790ee | 25 | //led1 = 0; |
szqt | 0:54f4263790ee | 26 | } |
szqt | 0:54f4263790ee | 27 | |
szqt | 0:54f4263790ee | 28 | void button2_pressed() |
szqt | 0:54f4263790ee | 29 | { |
szqt | 0:54f4263790ee | 30 | led1 = led2 =led3 =led4 = 1; |
szqt | 0:54f4263790ee | 31 | led2 = 0; |
szqt | 0:54f4263790ee | 32 | |
szqt | 0:54f4263790ee | 33 | } |
szqt | 0:54f4263790ee | 34 | |
szqt | 0:54f4263790ee | 35 | void button2_released() |
szqt | 0:54f4263790ee | 36 | { |
szqt | 0:54f4263790ee | 37 | led1 = led2 =led3 =led4 = 1; |
szqt | 0:54f4263790ee | 38 | //led1 = 0; |
szqt | 0:54f4263790ee | 39 | } |
szqt | 0:54f4263790ee | 40 | |
szqt | 0:54f4263790ee | 41 | void button3_pressed() |
szqt | 0:54f4263790ee | 42 | { |
szqt | 0:54f4263790ee | 43 | led1 = led2 =led3 =led4 = 1; |
szqt | 0:54f4263790ee | 44 | led3 = 0; |
szqt | 0:54f4263790ee | 45 | // wait(0.1); |
szqt | 0:54f4263790ee | 46 | } |
szqt | 0:54f4263790ee | 47 | |
szqt | 0:54f4263790ee | 48 | void button3_released() |
szqt | 0:54f4263790ee | 49 | { |
szqt | 0:54f4263790ee | 50 | led1 = led2 =led3 =led4 = 1; |
szqt | 0:54f4263790ee | 51 | //led1 = 0; |
szqt | 0:54f4263790ee | 52 | } |
szqt | 0:54f4263790ee | 53 | |
szqt | 0:54f4263790ee | 54 | void button4_pressed() |
szqt | 0:54f4263790ee | 55 | { |
szqt | 0:54f4263790ee | 56 | led1 = led2 =led3 =led4 = 1; |
szqt | 0:54f4263790ee | 57 | led4 = 0; |
szqt | 0:54f4263790ee | 58 | |
szqt | 0:54f4263790ee | 59 | } |
szqt | 0:54f4263790ee | 60 | |
szqt | 0:54f4263790ee | 61 | void button4_released() |
szqt | 0:54f4263790ee | 62 | { |
szqt | 0:54f4263790ee | 63 | led1 = led2 =led3 =led4 = 1; |
szqt | 0:54f4263790ee | 64 | //led1 = 0; |
szqt | 0:54f4263790ee | 65 | } |
szqt | 0:54f4263790ee | 66 | |
szqt | 0:54f4263790ee | 67 | |
szqt | 0:54f4263790ee | 68 | // main() runs in its own thread in the OS |
szqt | 0:54f4263790ee | 69 | // (note the calls to Thread::wait below for delays) |
szqt | 0:54f4263790ee | 70 | |
szqt | 0:54f4263790ee | 71 | int main() { |
szqt | 0:54f4263790ee | 72 | led1 = led2 =led3 =led4 = 0; |
szqt | 0:54f4263790ee | 73 | |
szqt | 0:54f4263790ee | 74 | button1.fall(&button1_pressed); |
szqt | 0:54f4263790ee | 75 | button1.rise(&button1_released); |
szqt | 0:54f4263790ee | 76 | |
szqt | 0:54f4263790ee | 77 | button2.fall(&button2_pressed); |
szqt | 0:54f4263790ee | 78 | button2.rise(&button2_released); |
szqt | 0:54f4263790ee | 79 | |
szqt | 0:54f4263790ee | 80 | button3.fall(&button3_pressed); |
szqt | 0:54f4263790ee | 81 | button3.rise(&button3_released); |
szqt | 0:54f4263790ee | 82 | |
szqt | 0:54f4263790ee | 83 | button4.fall(&button4_pressed); |
szqt | 0:54f4263790ee | 84 | button4.rise(&button4_released); |
szqt | 0:54f4263790ee | 85 | |
szqt | 0:54f4263790ee | 86 | |
szqt | 0:54f4263790ee | 87 | while (true) { |
szqt | 0:54f4263790ee | 88 | // led1 = !led1; |
szqt | 0:54f4263790ee | 89 | // wait(0.5); |
szqt | 0:54f4263790ee | 90 | // led2 = !led2; |
szqt | 0:54f4263790ee | 91 | // wait(0.5); |
szqt | 0:54f4263790ee | 92 | // led3 = !led3; |
szqt | 0:54f4263790ee | 93 | // wait(0.5); |
szqt | 0:54f4263790ee | 94 | // led4 = !led4; |
szqt | 0:54f4263790ee | 95 | // wait(0.5); |
szqt | 0:54f4263790ee | 96 | } |
szqt | 0:54f4263790ee | 97 | } |
szqt | 0:54f4263790ee | 98 |