Sunday, October 28, 2012

Morse "Paddle" Keyer

Building on our previous "simple" piezo beep sketch, I now introduce a Morse "Paddle" Keyer. It contains two buttons, one timed for a 60ms dot, the other for a 180ms dash. It uses the tone() command to activate the Piezo, which is a pwm output.




/*
 Piezo

This example shows a morse "paddle" keyer.
One button is timed for a dot, the other
for a dash (3 * dot). I'm using a 60ms
duration for a dot, so a dash = 180ms.


 */

int outPin = 9;
unsigned int frequency = 700;
unsigned long dotDuration = 60;
unsigned long dashDuration = dotDuration * 3;
int dotPin = 7;   // pushbutton connected to digital pin 7
int dashPin = 8;   // pushbutton connected to digital pin 8


void setup()  {
pinMode(dotPin, INPUT);      // sets the digital pin 7 as input
pinMode(dashPin, INPUT);      // sets the digital pin 8 as input
}

void loop()  {
  int dotVal=LOW;
  int dashVal=LOW;

  dotVal = digitalRead(dotPin);
  dashVal = digitalRead(dashPin);
 
  if (dotVal==HIGH)
{
  tone(outPin, frequency, dotDuration);
}
 
  if (dashVal==HIGH)
{
  tone(outPin, frequency, dashDuration);
}
}


What we are reading this week: