Landing : Athabascau University
  • Blogs
  • Assignment 0: My First Program

Assignment 0: My First Program

The first program that I decided to try out in the Arduino IDE is the "Blink" program. I copied the code straight from the Arduino Wikipedia article. It compiled and ran on the RedBoard with no issues.

BlinkScreenshot  BlinkVideo

After that, I decided to try to edit the code to make the LED blink faster. This new, faster version of Blink also compiled and ran on the RedBoard with no issues.

BlinkFastScreenshot  BlinkFastVideo

Next, I decided to use what I learned from the Blink program to write a program to make the LED blink my name (Adam) in morse code. I took a quick look at the Morse code Wikipedia article and learned that morse code is a series of "dits", "dahs", and "spaces". There is also a chart in the Wikipedia article that shows each letter of the English alphabet and its corresponding representation in morse code. With this new knowledge of morse code coupled with the knowledge I gained from the Blink program, I was able to write a program in the Arduino IDE to make the LED blink my name in morse code. This program compiled and ran on the RedBoard with no issues.

MorseCodeChart   MorseCodeVideo

The morse code program looks like this:

# define LED_PIN 13 // Pin number attached to LED.
void setup() {
// put your setup code here, to run once:
pinMode(LED_PIN, OUTPUT); // Configure pin 13 to be a digital output.
}
void loop() {
// put your main code here, to run repeatedly:
letterA();
longSpace();
letterD();
longSpace();
letterA();
longSpace();
letterM();
longerSpace();
}
void letterA(){
dit();
space();
dah();
}
void letterD(){
dah();
space();
dit();
space();
dit();
}
void letterM(){
dah();
space();
dah();
}
void dit(){
digitalWrite(LED_PIN, HIGH); // Turn on the LED.
delay(100); // Wait 0.1 seconds (100 milliseconds).
}
void dah(){
digitalWrite(LED_PIN, HIGH); // Turn on the LED.
delay(300); // Wait 0.3 seconds (300 milliseconds).
}
void space(){
digitalWrite(LED_PIN, LOW); // Turn off the LED.
delay(100); // Wait 0.1 seconds.
}
void longSpace(){
digitalWrite(LED_PIN, LOW); // Turn off the LED.
delay(300); // Wait 0.3 seconds.
}
void longerSpace(){
digitalWrite(LED_PIN, LOW); // Turn off the LED.
delay(700); // Wait 0.7 seconds.

Maybe in the future I will write a program that allows the RedBoard to produce morse code based on some input.