Assignment: Introduction to Arduino and Physical Computing
Collaborators:
/*
* BlinkMorse
*
* Blinks a Morse Code message when supplied with a string of dashes and dots.
* Todo 1: Take keyboard input of dashes and dots
* Todo 2: Take keyboard input of text, translate to Morse Code
*/
int ledPin = 13; // LED connected to digital pin 13
char code[]=".- .-. -.. ..- .. -. ---";
int i=0;
void setup() // run once, when the sketch starts
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
}
void loop() // run over and over again
{
while(code[i])
{
switch (code[i]) {
case '.':
dot();
break;
case '-':
dash();
break;
case ' ':
pause();
break;
}
i++;
}
i=0;
}
void dash()
{
digitalWrite(ledPin, HIGH); // sets the LED on
delay(600); // waits .6 seconds (twice as long as dot)
digitalWrite(ledPin, LOW); // sets the LED off
delay(300); // waits for .3 seconds
}
void dot()
{
digitalWrite(ledPin, HIGH); // sets the LED on
delay(300); // waits for .3 seconds
digitalWrite(ledPin, LOW); // sets the LED off
delay(300); // waits for .3 seconds
}
void pause()
{
delay(300);
}