acd52832_IR_led example.
Dependencies: aconno_bsp_Fork1 mbed
main.cpp@0:22939753aac7, 2016-09-21 (annotated)
- Committer:
- jurica238814
- Date:
- Wed Sep 21 11:49:08 2016 +0000
- Revision:
- 0:22939753aac7
acd52832_IR_led.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jurica238814 | 0:22939753aac7 | 1 | /* Copyright (c) 2016 Aconno. All Rights Reserved. |
jurica238814 | 0:22939753aac7 | 2 | * |
jurica238814 | 0:22939753aac7 | 3 | * Licensees are granted free, non-transferable use of the information. NO |
jurica238814 | 0:22939753aac7 | 4 | * WARRANTY of ANY KIND is provided. This heading must NOT be removed from |
jurica238814 | 0:22939753aac7 | 5 | * the file. |
jurica238814 | 0:22939753aac7 | 6 | * |
jurica238814 | 0:22939753aac7 | 7 | * aconno simple example program |
jurica238814 | 0:22939753aac7 | 8 | * IR LED sends "SOS" in the world |
jurica238814 | 0:22939753aac7 | 9 | */ |
jurica238814 | 0:22939753aac7 | 10 | |
jurica238814 | 0:22939753aac7 | 11 | |
jurica238814 | 0:22939753aac7 | 12 | #include "mbed.h" |
jurica238814 | 0:22939753aac7 | 13 | #include "acd52832_bsp.h" |
jurica238814 | 0:22939753aac7 | 14 | |
jurica238814 | 0:22939753aac7 | 15 | #define DOT_LENGTH 0.5 // Dot length (duration) in seconds |
jurica238814 | 0:22939753aac7 | 16 | #define DASH_LENGTH (DOT_LENGTH * 3) // Dash length (duration) |
jurica238814 | 0:22939753aac7 | 17 | #define ELEMENTS_PAUSE (DOT_LENGTH) // Pause between elements |
jurica238814 | 0:22939753aac7 | 18 | #define CHARS_PAUSE (DOT_LENGTH * 3) // Pause between characters |
jurica238814 | 0:22939753aac7 | 19 | #define WORDS_PAUSE (DOT_LENGTH *7) // Pause between words |
jurica238814 | 0:22939753aac7 | 20 | |
jurica238814 | 0:22939753aac7 | 21 | #define ON 1 |
jurica238814 | 0:22939753aac7 | 22 | #define OFF 0 |
jurica238814 | 0:22939753aac7 | 23 | |
jurica238814 | 0:22939753aac7 | 24 | |
jurica238814 | 0:22939753aac7 | 25 | DigitalOut IrLED(PIN_IRLED); |
jurica238814 | 0:22939753aac7 | 26 | |
jurica238814 | 0:22939753aac7 | 27 | void dot(DigitalOut LED){ |
jurica238814 | 0:22939753aac7 | 28 | // Turn IR LED ON |
jurica238814 | 0:22939753aac7 | 29 | LED = ON; |
jurica238814 | 0:22939753aac7 | 30 | wait(DOT_LENGTH); |
jurica238814 | 0:22939753aac7 | 31 | // Turn it off |
jurica238814 | 0:22939753aac7 | 32 | LED = OFF; |
jurica238814 | 0:22939753aac7 | 33 | wait(ELEMENTS_PAUSE); |
jurica238814 | 0:22939753aac7 | 34 | } |
jurica238814 | 0:22939753aac7 | 35 | |
jurica238814 | 0:22939753aac7 | 36 | void dash(DigitalOut LED){ |
jurica238814 | 0:22939753aac7 | 37 | // Turn IR LED ON |
jurica238814 | 0:22939753aac7 | 38 | LED = ON; |
jurica238814 | 0:22939753aac7 | 39 | wait(DASH_LENGTH); |
jurica238814 | 0:22939753aac7 | 40 | // Turn it off |
jurica238814 | 0:22939753aac7 | 41 | LED = OFF; |
jurica238814 | 0:22939753aac7 | 42 | wait(ELEMENTS_PAUSE); |
jurica238814 | 0:22939753aac7 | 43 | } |
jurica238814 | 0:22939753aac7 | 44 | |
jurica238814 | 0:22939753aac7 | 45 | void S_code(DigitalOut LED){ |
jurica238814 | 0:22939753aac7 | 46 | dot(LED); |
jurica238814 | 0:22939753aac7 | 47 | dot(LED); |
jurica238814 | 0:22939753aac7 | 48 | dot(LED); |
jurica238814 | 0:22939753aac7 | 49 | } |
jurica238814 | 0:22939753aac7 | 50 | |
jurica238814 | 0:22939753aac7 | 51 | void O_code(DigitalOut LED){ |
jurica238814 | 0:22939753aac7 | 52 | dash(LED); |
jurica238814 | 0:22939753aac7 | 53 | dash(LED); |
jurica238814 | 0:22939753aac7 | 54 | dash(LED); |
jurica238814 | 0:22939753aac7 | 55 | } |
jurica238814 | 0:22939753aac7 | 56 | |
jurica238814 | 0:22939753aac7 | 57 | |
jurica238814 | 0:22939753aac7 | 58 | int main(){ |
jurica238814 | 0:22939753aac7 | 59 | while(1){ |
jurica238814 | 0:22939753aac7 | 60 | S_code(IrLED); |
jurica238814 | 0:22939753aac7 | 61 | wait(CHARS_PAUSE); |
jurica238814 | 0:22939753aac7 | 62 | O_code(IrLED); |
jurica238814 | 0:22939753aac7 | 63 | wait(CHARS_PAUSE); |
jurica238814 | 0:22939753aac7 | 64 | S_code(IrLED); |
jurica238814 | 0:22939753aac7 | 65 | wait(WORDS_PAUSE); |
jurica238814 | 0:22939753aac7 | 66 | } |
jurica238814 | 0:22939753aac7 | 67 | } |