What I tried to do was have a millis counter for the period of a dot and dash and letter space. It seems like there must be an easier way then having a millis counter for each one. This program does upload and will light but not blink the led when those letters are typed.
#define dotPeriod 250
#define dashPeriod (dotPeriod*3)
#define relaxTime (dotPeriod)
#define letterSpace (dotPeriod*3)
#define wordSpace (dotPeriod*7)
#define flash ( digitalWrite(ledPin,ledState))
const int ledPin = 13; // the number of the LED pin
int leddotState = LOW;
int leddashState = LOW;
int ledwordspaceState = HIGH;
long previousdotMillis = 0;
long previousdashMillis = 0;
long previouswordspaceMillis = 0;
void dot(){
digitalWrite(ledPin,leddotState);
}
void dash(){
digitalWrite(ledPin,leddashState);
}
void wordspace(){
digitalWrite(ledPin,ledwordspaceState);
}
void setup(){
Serial.begin(9600);
// set the digital pin as output:
pinMode(ledPin, OUTPUT);
}
void loop(){
unsigned long currentdotMillis = millis();
unsigned long currentdashMillis = millis();
unsigned long currentwordspaceMillis = millis();
if(currentdotMillis - previousdotMillis > dotPeriod) {
// save the last time you blinked the LED
previousdotMillis = currentdotMillis;
// if the LED is off turn it on and vice-versa:
if (leddotState == LOW)
leddotState = HIGH;
else
leddotState = LOW;
if(currentdashMillis - previousdashMillis > dashPeriod) {
// save the last time you blinked the LED
previousdashMillis = currentdashMillis;
// if the LED is off turn it on and vice-versa:
if (leddashState == LOW)
leddashState = HIGH;
}
else
leddashState = LOW;
if(currentwordspaceMillis - previouswordspaceMillis > letterSpace) {
// save the last time you blinked the LED
previouswordspaceMillis = currentwordspaceMillis;
// if the LED is off turn it on and vice-versa:
if (ledwordspaceState == LOW)
ledwordspaceState = HIGH;
else
ledwordspaceState = LOW;
if (Serial.available() > 0) {
int inByte = Serial.read();
switch (inByte) {
case 'a':
dot();
break;
case 'b':
dot;
dot;
dash;
break;
case 'c':
dash;
dot;
dot;
break;
case 'd':
dot;
dash;
dot;
dot;
break;
case 'e':
dash ;
dot ;
dash;
break;
case ' ':
wordspace();
break;
}
}
}
}
}