come with me, on the way I'll explain.
Morse Code Translator with Arduino
You write in your computer, sends a message thought USB and Arduino translates it into a Morse code.
Just a Arduino board with a buzzer connected at the digital output 12 (one wire in the ground and the other in the 12).
I tried to make the code as general as possible so you can easily adapt it for anthers ways of transmitting a Morse code. To do that you just need to rewrite a few functions.
+-------------------+
| 3) Interpretation |
+-------------------+
| 2) Translation |
+-------------------+ +-------------------+
| Computer |<========USB (Serial)=======>| 1) Reading |
+-------------------+ +-------------------+
- Reads a character from Serial. Main function loop().
- Translate a ascii char into a Morse code using a reference table. A letter 'K' becomes a string word "-.-". Function say_char().
- Interpret the Morse word as light and sound. Mostly at function say_morse_word(). The Interpretation needs 5 functions to say all Morse words, dot(), dash(), shortgap(), mediumgap() and intragap().
For a more details on Morse code I strongly recommend the English Wikipedia article on it.
int led = 13; // LED connected to digital pin 13 int buzzer = 12; // buzzer connected to digital pin 12 int unit = 50; // duration of a pulse char * morsecode[] = { "-----", // 0 ".----", // 1 "..---", // 2 "...--", // 3 "....-", // 4 ".....", // 5 "-....", // 6 "--...", // 7 "---..", // 8 "----.", // 9 "---...", // : "-.-.-.", // ; "", // < (there's no morse for this simbol) "-...-", // = "", // > (there's no morse for this simbol) "..--..", // ? ".--._.", // @ ".-", // A "-...", // B "-.-.", // C "-..", // D ".", // E "..-.", // F "--.", // G "....", // H "..", // I ".---", // J "-.-", // K ".-..", // L "--", // M "-.", // N "---", // O ".--.", // P "--.-", // Q ".-.", // R "...", // S "-", // T "..-", // U "...-", // V ".--", // W "-..-", // X "-.--", // Y "--.." // Z }; void setup() { pinMode(led, OUTPUT); pinMode(buzzer, OUTPUT); Serial.begin(9600); } void say_morse_word(char * msg){ int index = 0; while(msg[index]!='\0'){ // say a dash if(msg[index]=='-'){ dash(); } // say a dot if(msg[index]=='.'){ dot(); } // gap beetween simbols intragap(); index++; } } // beep void beep(int time){ int i; int t = 100; // period of the wav. bigger means lower pitch. int beepduration = (int)((float)time/t*1800); digitalWrite(led, HIGH); for(i=0;i<beepduration;i++){ digitalWrite(buzzer, HIGH); delayMicroseconds(t); digitalWrite(buzzer, LOW); delayMicroseconds(t); } delay(time); } // silence void silence(int time){ digitalWrite(led, LOW); delay(time); } // general procedure for . void dot() { beep(unit); } // general procedure for - void dash() { beep(unit*3); } // gap between dots and dashes void intragap() { silence(unit); } // gap between letters void shortgap() { silence(3*unit); } // gap be tween words void mediumgap() { silence(7*unit); } void say_char(char letter){ if((letter>='0')&&(letter<='Z')&&(letter!='<')&&(letter!='>')){ Serial.print(morsecode[letter-'0']); Serial.print(' '); say_morse_word(morsecode[letter-'0']); shortgap(); } else { if(letter==' '){ Serial.print(" \\ "); mediumgap(); }else{ Serial.print("X"); } } } void loop(){ if(Serial.available()){ say_char((char)Serial.read()); } }
Additionally you can put another function to say entire strings, like say_string("HELLO WORLD")
void say_string(char * asciimsg){ int index = 0; char charac; charac = asciimsg[index]; while(charac!='\0'){ say_char(morsecode[charac-'0']); Serial.println(morsecode[charac-'0']); charac = asciimsg[++index]; shortgap(); } }
You can use the Arduino IDE itself or any other program that talks with the serial port USB.
No trackbacks yet.
Getting an Android app source
18 March, 2010 - 12:00 am
Tags: Android, branch, cmd, git, programming
Posted in english | No comments
Getting the Android’s AlarmClock application source from official repositories:
git clone git://android.git.kernel.org/platform/packages/apps/AlarmClock.git
To get the head version for an old platform like the 1.4 (codename donut), choose the correspondent branch using -o or –origin:
git clone git://android.git.kernel.org/platform/packages/apps/AlarmClock.git –origin donut
Getting enviroment information on Android
16 March, 2010 - 10:18 am
Tags: Android, Eclipse, Java, programming, who am i, whoami
Posted in english | 3 comments
This is a simple program I wrote called Who Am I that shows informations about the device which it is running. Which can be useful for developers and maybe advanced users.
Download:
WhoAmI.tar.bz2 – Eclipse project. It’s configured for Android platform 4 (1.6) but should work without problems in newer Android platform versions.
WhoAmI.apk – Application installation Android [...]
The Caps Lock Java Socket Server
27 February, 2010 - 9:39 pm
Tags: caps lock, Java, programming, socket, upcase
Posted in english | No comments
Here is a simple server for those who are starting studying sockets or just needs a simple socket server example for reuse while writing your own behavior.
Features:
A client should enter a string and the server would answer the same string, with each symbol in up case, when possible.
Default port at 8080.
One client at time.
No multi [...]
Beware the locale
22 February, 2010 - 5:16 pm
Tags: development, i18n, Java, JUnit, locale, programming, String, teste unitário, toString, unit testing
Posted in english | No comments
Today I was programming a toString method for a class widely used in a application, using the very useful String.format that provides a C’s like printf formatter.
@Override
public String toString() {
return String.format("VO[a: %.1f, b: %.1f, c: %.1f]", a, b, a+b);
}
%.1f means a float with one digit precision after the dot separator. The code [...]
Miojo Script
28 January, 2010 - 2:37 am
Tags: libnotify, Linux, miojo, notify, notify-send, programming, Shell Script, ubuntu
Posted in english | 1 comment
O pre-requisito é o notify-send, um utilitário de linha de comando do libnotify. No Ubuntu:
sudo aptitude install libnotify-bin
E aqui o script em si:
sleep 5m; notify-send “aviso” “tirar o miojo do fogo”
Pronto, depois de cinco minutos isso vai aparecer:
Easily Sortable Date and Time Representation
20 January, 2010 - 10:55 pm
Tags: date, datetime, ISO 8601, Jochen Voss, Markus Kuhn, programming, Python, representation, sort, sorting, time
Posted in english | No comments
I was looking for a date and time representation useful for registering stock quotes in a simple plain file.
I found that the standard ISO 8601 is just the answer for this, it’s called “Data elements and interchange formats — Information interchange — Representation of dates and times”. Here is a example:
2010-01-20 22:14:38
There’s this good article from [...]
Java Font List
5 January, 2010 - 6:10 pm
Tags: AWT, fonts, Java, JVM, Larabie, Larabie Fonts, programming
Posted in english | Comments Off
Here’s a program that lists fonts available in your JVM. You can also set the environment variable JAVA_FONTS to specify the font directory.
import java.awt.GraphicsEnvironment;
public class ListFonts {
public static void main(String args[]){
GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment();
for(String font:e.getAvailableFontFamilyNames()){
System.out.println(font);
}
}
}
By using pipes you can count how many fonts you have:
java ListFonts|wc -l
On my Ubuntu machine here I got 556 because [...]
Python Fast XML Parsing
25 December, 2009 - 3:04 pm
Tags: dtd, expat, game, programming, pygame, Python, sax, schema, urllib, XML
Posted in english | 1 comment
Here is a useful tip on Python XML decoding.
I was extending xml.sax.ContentHandler class in a example to decode maps for a Pygame application when my connection went down and I noticed that the program stop working raising a exception regarded a call to urlib (a module for retrieve resources by url). I noticed that the [...]
Tiled TMX Map Loader for Pygame
I’m using the Tiled Map Editor for a while, I even wrote that tutorial about it. It’s a general purpose tile map editor, written in Java but now migrating to C++ with Qt, that can be easily used with my set of free pixelart tiles.
A map done with Tiled is stored in a file with [...]
Pygame: Running Orcs
11 December, 2009 - 7:47 am
Tags: game, orc, Pixelart, programming, pygame, Python
Posted in english | No comments
Here is a Pygame Sprite animation using the approach presented by Joe Wreschnig and Nicolas Crovatti. It’s not yet exactly what I need but is very suitable.
import pygame, random
from pygame.locals import *
class Char(pygame.sprite.Sprite):
x,y = (100,0)
def __init__(self, img, frames=1, modes=1, w=32, h=32, fps=3):
pygame.sprite.Sprite.__init__(self)
original_width, original_height = img.get_size()
self._w = w
self._h = h
self._framelist = []
for i in xrange(int(original_width/w)):
self._framelist.append(img.subsurface((i*w,0,w,h)))
self.image = [...]














24 October, 2009 - 3:56 am
Great stuff!
What do you think, on the other side, could there be a Morse code -> Text translating Arduino? That would be pretty practical….
24 October, 2009 - 1:32 pm
Greg, seems a good idea.
25 October, 2009 - 11:54 am
@Greg: I will start to work on such a project in the coming weeks. An Arduino will be connected to an LCD display that displays the translation from morse input. Way to input morse will be non standard. Project is to be used as a communication tool for a person with severe physical disabilities.
30 October, 2009 - 9:13 pm
Yes, I would like to see an example of a working morse decoder with LCD!
Great! Thanks!
23 November, 2009 - 12:11 am
I’m just starting on my arduino and want to know how to go about decoding morse and display to an LCD my self thanks!!!
Nice work
Chad