#include <retrieval.h>
const int laserPin = 7; // laser attch to
static int dotDelay = 200;
void setup() {
// put your setup code here, to run once:
pinMode(laserPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
char ch = 0; // store the character or digit read from the serial monitor
if (Serial.available() > 0) {
// is there anything to read
ch = Serial.read(); // read a single letter from serial monitor
}
morseSignal(ch); // flashes depend on the letter
}
void flashDot(char cha) {
digitalWrite(laserPin, HIGH);
if (cha == '.') {
delay(dotDelay);
} else {
delay(dotDelay * 3); // gap between letters
}
}
void flashSequence(char *sequence) {
int i = 0;
while (sequence[i] != NULL) {
flashDot(sequence[i]);
i++;
}
delay(dotDelay * 3);
}
void morseSignal(char ch) {
if (ch >= 'a' && ch <= 'z') {
flashSequence(letters[ch - 'a']);
} else if (ch >= 'A' && ch <= 'Z') {
flashSequence(letters[ch - 'A']);
} else if (ch >= '0' && ch <= 9) {
flashSequence(numbers[ch - '0']);
} else if (ch == ' ') {
delay(dotDelay * 4); // gap between words
}
}