Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define ALPH_LEN 26
- #define UNIT 100
- #include "nrf_delay.h"
- void morse(char ch, int led)
- {
- /* even numbers represent a code of a letter
- * e.g.: -... -> 0111 -> 1110 -> 0xe
- * odd numbers represent the length of a character
- */
- static char code[ALPH_LEN*2] = {
- 0x1,2, 0xe,4, 0xa,4, 0x6,3, 0x1,1, 0xb,4, 0x4,3, 0xf,4, 0x3,2, 0x1,4,
- 0x2,3, 0xd,4, 0x0,2, 0x2,2, 0x0,3, 0x9,4, 0x4,4, 0x5,3, 0x7,3, 0x0,1,
- 0x3,3, 0x7,4, 0x1,3, 0x6,4, 0x2,4, 0xc,4
- };
- if (ch == ' ') {
- nrf_delay_ms(UNIT*4);
- return;
- }
- if (ch < 'a' || ch > 'z') return;
- char letter = code[2*(ch - 'a')];
- char count = code[2*(ch - 'a') + 1];
- char signal;
- for (char i = 0; i < count; ++i) {
- signal = letter & 1;
- bsp_board_led_invert(led);
- nrf_delay_ms(UNIT * (signal ? 1 : 3));
- bsp_board_led_invert(led);
- letter >>= 1;
- nrf_delay_ms(UNIT);
- }
- nrf_delay_ms(UNIT*3);
- }
- #undef UNIT
- #undef ALPH_LEN
Add Comment
Please, Sign In to add comment