[vc_row][vc_column width=”1/1″][vc_column_text]The components used in this experiment are shown below:
The components are one diode, one 470 ohm resistor,2 jumper wires and one breadboard.
Schematics:
The long pin of LED is positive, and the short pin is negative.
Wiring Diagram:
Arduino Code:
int ledPin = 9;
char* letters[] = {
“.-“, “-…”, “-.-.”, “-..”, “.”, “..-.”, “–.”, “….”, “..”, // A-I
“.—“, “-.-“, “.-..”, “–“, “-.”, “—“, “.–.”, “–.-“, “.-.”, // J-R
“…”, “-“, “..-“, “…-“, “.–“, “-..-“, “-.–“, “–..” // S-Z
};
char* numbers[] = {“—–“, “.—-“, “..—“, “…–“, “….-“, “…..”, “-
….”, “–…”, “—..”, “—-.”};
int dotDelay = 200;
void setup()
{
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop()
{
char ch;
if (Serial.available()) // is there anything to be read from USB?
{
ch = Serial.read(); // read a single letter
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
}
}
}
void flashSequence(char* sequence)
{
int i = 0;
while (sequence[i] != NULL) {
flashDotOrDash(sequence[i]);
i++;
}
delay(dotDelay * 3); // gap between letters
}
void flashDotOrDash(char dotOrDash)
{
digitalWrite(ledPin, HIGH);
if (dotOrDash == ‘.’) {
delay(dotDelay);
}
else // must be a – {
delay(dotDelay * 3);
}
digitalWrite(ledPin, LOW);
delay(dotDelay); // gap between flashes
}[/vc_column_text][/vc_column][/vc_row]
Leave a Reply
You must be logged in to post a comment.