Skip to content

Instantly share code, notes, and snippets.

@dwhacks
Created May 8, 2014 02:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dwhacks/480bafeaf9674c225269 to your computer and use it in GitHub Desktop.
Save dwhacks/480bafeaf9674c225269 to your computer and use it in GitHub Desktop.
some arduino morse, correct table
//
//Arduino Nano Beacon ver 1.0
// Written by Michele Casali Iz3klb
// Email: iz3klb@yahoo.it
//
// This code is so trivial that I'm releasing it completely without
// restrictions. If you find it useful, it would be nice if you dropped
// me an email. Feel free to use whatever.
//
struct t_mtab { char c, pat; } ;
struct t_mtab morsetab[] = {
{'.', 106},
{',', 115},
{'?', 76},
{'/', 41},
{'A', 6},
{'B', 17},
{'C', 21},
{'D', 9},
{'E', 2},
{'F', 20},
{'G', 11},
{'H', 16},
{'I', 4},
{'J', 30},
{'K', 13},
{'L', 18},
{'M', 7},
{'N', 5},
{'O', 15},
{'P', 22},
{'Q', 27},
{'R', 10},
{'S', 8},
{'T', 3},
{'U', 12},
{'V', 24},
{'W', 14},
{'X', 25},
{'Y', 29},
{'Z', 19},
{'1', 62},
{'2', 60},
{'3', 56},
{'4', 48},
{'5', 32},
{'6', 33},
{'7', 35},
{'8', 39},
{'9', 47},
{'0', 63}
} ;
#define N_MORSE (sizeof(morsetab)/sizeof(morsetab[0]))
#define SPEED (12)
#define DOTLEN (1200/SPEED)
#define DASHLEN (3*(1200/SPEED))
#define UNDERSCORELEN (3*(1200/SPEED)) //qui metti i 5 secondi
int LEDpin = 13 ;
void
underscoreDash()
{
digitalWrite(LEDpin, HIGH) ;
delay(UNDERSCORELEN);
digitalWrite(LEDpin, LOW) ;
delay(DOTLEN) ;
}
void
dash()
{
digitalWrite(LEDpin, HIGH) ;
delay(DASHLEN);
digitalWrite(LEDpin, LOW) ;
delay(DOTLEN) ;
}
void
dit()
{
digitalWrite(LEDpin, HIGH) ;
delay(DOTLEN);
digitalWrite(LEDpin, LOW) ;
delay(DOTLEN);
}
void
send(char c)
{
int i ;
if (c == '_') {
Serial.print(c) ;
underscoreDash() ;
return ;
}
if (c == ' ') {
Serial.print(c) ;
delay(7*DOTLEN) ;
return ;
}
for (i=0; i<N_MORSE; i++) {
if (morsetab[i].c == c) {
unsigned char p = morsetab[i].pat ;
Serial.print(morsetab[i].c) ;
while (p != 1) {
if (p & 1)
dash() ;
else
dit() ;
p = p / 2 ;
}
delay(2*DOTLEN) ;
return ;
}
}
/* if we drop off the end, then we send a space */
Serial.print("?") ;
}
void
sendmsg(char *str)
{
while (*str)
send(*str++) ;
Serial.println("");
}
void setup() {
pinMode(LEDpin, OUTPUT) ;
Serial.begin(9600) ;
Serial.println("Simple Arduino Morse Beacon v1.0") ;
Serial.println("Written by Michele Casali <iz3klb@yahoo.it>") ;
Serial.println("Check out site @ http://iz3klb.it") ;
Serial.println("") ;
}
void loop() {
sendmsg("VVV IZ3KLB/B JN55tt PWR5W PSE QSL") ;
delay(5000) ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment