Decidi fazer um keyer morse mais sofisticado ques os anteriores, tem de ter como caracteristicas :
– Função de keyer para usar em radios que só suportem chave simples.
– Velocidade ajustável.
– Produzir som por si proprio de modo a usar para treino.
Optei por uma solução baseada em arduino.
Lista de material :
– Arduino Uno.
– Shield de prototipos.
– Modulo de 1 Relé.
– Modulo de buzzer.
– Modulo de rotary encoder.
– 2 Resistências de 47k.
– 1 jack audio stereo.
– 1 jack audio mono.
O Código é o seguinte :
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keyboard.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
#define outputA 6
#define outputB 7
#define encoderSW 5
#define P_DOT 2 //Dit
#define P_DASH 3 // Dah
#define P_AUDIO 8 // Audio out (buzzer)
#define P_CW 4 // key
#define MAX_KEY_SPEED 99
int speed=64;
int counter = 64;
int aState;
int aLastState;
unsigned long t1,t2;
String letra;
String prevletra;
String scroolingline1;
String scroolingline2;
///Letter decoder
String getLetter(String in){
String l="";
if(in=="._"){
l="A";
}else if (in=="_..."){
l="B";
}else if (in=="_._."){
l="C";
}else if (in=="_.."){
l="D";
}else if (in=="."){
l="E";
}else if (in==".._."){
l="F";
}else if (in=="__."){
l="G";
}else if (in=="...."){
l="H";
}else if (in==".."){
l="I";
}else if (in==".___"){
l="J";
}else if (in=="_._"){
l="K";
}else if (in=="._.."){
l="L";
}else if (in=="__"){
l="M";
}else if (in=="_."){
l="N";
}else if (in=="___"){
l="O";
}else if (in==".__."){
l="P";
}else if (in=="__._"){
l="Q";
}else if (in=="._."){
l="R";
}else if (in=="..."){
l="S";
}else if (in=="_"){
l="T";
}else if (in==".._"){
l="U";
}else if (in=="..._"){
l="V";
}else if (in==".__"){
l="W";
}else if (in=="_.._"){
l="X";
}else if (in=="_.__"){
l="Y";
}else if (in=="__.."){
l="Z";
}else if (in==".____"){
l="1";
}else if (in=="..___"){
l="2";
}else if (in=="...__"){
l="3";
}else if (in=="...._"){
l="4";
}else if (in=="....."){
l="5";
}else if (in=="_...."){
l="6";
}else if (in=="__..."){
l="7";
}else if (in=="___.."){
l="8";
}else if (in=="____."){
l="9";
}else if (in=="_____"){
l="0";
}else if (in=="..__.."){
l="?";
}else if (in=="._._._"){
l=".";
}else if (in=="__..__"){
l=",";
}else if (in=="_.._."){
l="/";
}else if (in=="_..._"){
l="=";
}
return(l);
}
// Initialize
void setup()
{
//keyer pins
pinMode(P_DOT, INPUT);
pinMode(P_DASH, INPUT);
pinMode(encoderSW, INPUT);
pinMode(P_AUDIO, OUTPUT);
pinMode(P_CW, OUTPUT);
digitalWrite(P_CW, LOW); // key up
//speed encoder
pinMode (outputA,INPUT);
pinMode (outputB,INPUT);
Serial.begin (9600);
// Reads the initial state of the outputA
aLastState = digitalRead(outputA);
// initialize the LCD
lcd.begin();
// Turn on the blacklight
lcd.setBacklight((uint8_t)1);
lcd.setCursor(0,0);
lcd.print("BELKADOG.COM");
lcd.setCursor(0,2);
scroolingline1=" ";
scroolingline2=" ";
letra = "";
t1=millis();
//Keyer speed
lcd.setCursor(0,3);
lcd.print("Key Delay : ");
lcd.print(speed);
}
// Main routine
void loop()
{
//////////////////////////////////////////////////////////////////////////
//// ////
//// Keyer ////
//// ////
//////////////////////////////////////////////////////////////////////////
if(!digitalRead(P_DOT))
{
keyAndBeep(speed);
delay(speed);
letra=letra+".";
t1=millis();
}
if(!digitalRead(P_DASH))
{
keyAndBeep(speed*3);
delay(speed);
letra=letra+"_";
t1=millis();
}
//espaço de pouco mais de um dash... nova letra
if ((millis()-t1)>speed*3){
if (letra!=""){
if (getLetter(letra)!=""){
Serial.print(getLetter(letra));
lcd.setCursor(1,1);
scroolingline2=scroolingline1.substring(1,18)+ getLetter(letra);
lcd.print(scroolingline2);
scroolingline1=scroolingline2;
lcd.setCursor(0,3);
lcd.print("Key Delay : ");
lcd.print(speed);
}else{
Serial.print(letra);
}
prevletra=letra;
letra="";
}
}
//////////////////////////////////////////////////////////////////////////
//// ////
//// Encoder ////
//// ////
//////////////////////////////////////////////////////////////////////////
aState = digitalRead(outputA); // Reads the "current" state of the outputA
// If the previous and the current state of the outputA are different, that means a Pulse has occured
if (aState != aLastState){
// If the outputB state is different to the outputA state, that means the encoder is rotating clockwise
if (digitalRead(outputB) != aState) {
counter ++;
} else {
counter --;
}
Serial.print("Speed: ");
Serial.println(counter);
lcd.setCursor(0,3);
lcd.print("Key Delay : ");
lcd.setCursor(16,3);
lcd.print(speed);
if (counter>MAX_KEY_SPEED){
counter=MAX_KEY_SPEED;
}
if (counter<1){
counter=1;
}
speed=counter;
}
aLastState = aState;
}
//////////////////////////////////////////////////////////////////////////
//// ////
//// Som ////
//// ////
//////////////////////////////////////////////////////////////////////////
void keyAndBeep(int speed)
{
digitalWrite(P_CW, HIGH); // Key down
for (int i=0; i < (speed); i++) // Beep loop
{
digitalWrite(P_AUDIO, HIGH);
delay(1);
}
digitalWrite(P_AUDIO, LOW);
delay(1);
digitalWrite(P_CW, LOW); // Key up
}