I am programming on a Tiny85 board which doesn't really have good serial output capabilities.
In the case of a simple configuration error, I thought of blinking a brief description of the error state in Morse code instead of a Serial.println()
. So, here is my Morse code sketch. I hope somebody finds it useful.
Bonus: explain to me how to make this into a library rather than just a standalone sketch.
Arduino Morse Code Blink
Copyright © 2021 Douglas Held
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
/*
Morse Blinking library for an LED
*/
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode( LED_BUILTIN, OUTPUT );
}
// General speed of coding in ms. Length of one 'dit'.
const int BEAT = 175;
void on( int ms ){
digitalWrite( LED_BUILTIN, HIGH ); // turn the LED on (HIGH is the voltage level)
delay( ms );
}
void off( int ms ){
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay( ms );
}
void dit(){
on( BEAT );
off( BEAT );
}
void dah(){
on( BEAT * 3 );
off( BEAT );
}
void blink( char c ){
switch (c) {
case 'a': dit(); dah(); break;
case 'b': dah(); dit(); dit(); dit(); break;
case 'c': dah(); dit(); dah(); dit(); break;
case 'd': dah(); dit(); dit(); break;
case 'e': dit(); break;
case 'f': dit(); dit(); dah(); dit(); break;
case 'g': dah(); dah(); dit(); break;
case 'h': dit(); dit(); dit(); dit(); break;
case 'i': dit(); dit(); break;
case 'j': dit(); dah(); dah(); dah(); break;
case 'k': dah(); dit(); dah(); break;
case 'l': dit(); dah(); dit(); dit(); break;
case 'm': dah(); dah(); break;
case 'n': dah(); dit(); break;
case 'o': dah(); dah(); dah(); break;
case 'p': dit(); dah(); dah(); dit(); break;
case 'q': dah(); dah(); dit(); dah(); break;
case 'r': dit(); dah(); dit(); break;
case 's': dit(); dit(); dit(); break;
case 't': dah(); break;
case 'u': dit(); dit(); dah(); break;
case 'v': dit(); dit(); dit(); dah(); break;
case 'w': dit(); dah(); dah(); break;
case 'x': dah(); dit(); dit(); dah(); break;
case 'y': dah(); dit(); dah(); dah(); break;
case 'z': dah(); dah(); dit(); dit(); break;
case '1' : dit(); dah(); dah(); dah(); dah(); break;
case '2' : dit(); dit(); dah(); dah(); dah(); break;
case '3' : dit(); dit(); dit(); dah(); dah(); break;
case '4' : dit(); dit(); dit(); dit(); dah(); break;
case '5' : dit(); dit(); dit(); dit(); dit(); break;
case '6' : dah(); dit(); dit(); dit(); dit(); break;
case '7' : dah(); dah(); dit(); dit(); dit(); break;
case '8' : dah(); dah(); dah(); dit(); dit(); break;
case '9' : dah(); dah(); dah(); dah(); dit(); break;
case '0' : dah(); dah(); dah(); dah(); dah(); break;
case ' ': off( BEAT * 4 ); break; // timing between words should total 700ms
}
off( BEAT * 3 ); // timing to separate a character
}
void loop() {
blink( 's' );
blink( 'o' );
blink( 's' );
blink( ' ' );
blink( 'a' );
blink( 'b' );
blink( 'c' );
blink( 'd' );
blink( 'e' );
blink( ' ' );
}