a MIDI-to-Morse code application.

Dependencies:   MIDI REnc button mbed morse

main.cpp

Committer:
ChuckTimber
Date:
2014-07-07
Revision:
2:5fe4a1431347
Parent:
1:d1e13b283169
Child:
3:993b88218184

File content as of revision 2:5fe4a1431347:

#include "mbed.h"

#define FREQ 800
DigitalOut myled(LED1);

char* codes[] = { ".-", "-...", "-.-.", "-..", ".", 
                  "..-.", "--.", "....", "..", ".---",
                  "-.-", ".-..", "--", "-.", "---", 
                  ".--.", "--.-", ".-.", "...", "-",
                  "..-", "...-", ".--", "-..-", "-.--", "--..", " " };
char* nums[] = { "-----", ".----", "..---", "...--", "....-",
                 ".....", "-....", "--...", "---..", "----." };

float cw_tick = 0.1;

PwmOut __pwm( dp24 );

void BeepOFF (void)
{
    __pwm.write(0.0);
}

void BeepON (void)
{
    __pwm.write(0.5);
}

void dot (void)
{
    BeepON(); myled = 1;
    wait(cw_tick);
    BeepOFF(); myled = 0;
}

void dash (void)
{
    BeepON(); myled = 1;
    wait(cw_tick*3);
    BeepOFF(); myled = 0;
}

void space(int k)
{
    wait(cw_tick * (float)k);
}


void space1(void)
{
    wait(cw_tick);
}

void space3(void)
{
    wait(cw_tick*3);
}

void space9(void)
{
    wait(cw_tick*9);
}

enum { ON, SPACE };

int main() {
    int i;
    char* ptr;

    {
        __pwm.period(1.0/FREQ);
        __pwm.write(0.0);
    };

    while(1) {
        for (i = 0; i < 27; i++) {
            ptr = codes[i];

            for (; *ptr; ptr++, space(1) ) {
                switch (*ptr) {
                case '-': dash();   break;
                case '.': dot();    break;
                case ' ': space(7); break;
                default:            continue;
                }
            }
            space(2);

        }
    }
}