Yoji Shidara / hello

Hello World form mbed

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 DigitalOut myled(LED1);
00004 
00005 char *morse_pattern[] = {
00006   "._", "_...", "_._.", "_..", ".", ".._.", "__.",
00007   "....", "..", ".___", "_._", "._..", "__",
00008   "_.", "___", ".__.", "__._", "._.", "...", "_",
00009   ".._", "..._", ".__", "_.._", "__._", "__.."
00010 };
00011 
00012 void morse(float time, char *str) {
00013   int i, j;
00014 
00015   for (i=0; i<strlen(str); i++) {
00016     char *c = str+i;
00017     if ('A' <= *c && *c <= 'Z') {
00018       char *pattern = morse_pattern[*c - 'A'];
00019       for (j=0; j<strlen(pattern); j++) {
00020         myled = 1;
00021         if(pattern[j] == '.') {
00022           wait(time * 1);
00023         } 
00024         else {
00025           wait(time * 3);
00026         }
00027         myled = 0;
00028         wait(time * 1);
00029       }
00030       wait(time * 2);
00031     } else {
00032       wait(time * 3);
00033     }
00034   }
00035   wait(time * 4);
00036 }
00037 
00038 int main() {
00039     char *str = "HELLO WORLD";
00040     
00041     while(1) {
00042         morse(0.1, str);
00043     }
00044 }