In our first week in the Hackers group, we began with an intro to what we do, which is to help people work on their own projects. In the first few weeks, we will focus on learning some useful technologies that people can then start applying to their own work.
Everyone introduced themselves and talked about what projects, if any, they planned to work on, and the mentors suggested some possible technologies that may be useful.
We decided to start by learning how to program the Arduino, which is a microcontroller that runs one program at a time – as soon as it is powered up, it runs the code in a function called setup(), and then it keeps running code in a function called loop().
Arduino is programmed in a version of the C Programming Language, which is a very well-known language.
To write a new program for Arduino, you connect it to a computer and use the Arduino IDE (interactive development environment), which we downloaded here: https://www.arduino.cc/en/Main/Software
Arduino is mainly used to control hardware, and we will see how to do that in future weeks. For this week, we did not control external hardware, but just a built-in LED.
We began by following this tutorial to write code to make an LED blink: https://www.arduino.cc/en/tutorial/blink
Then we started expanding it …
- We decided to flash an SOS message in Morse Code
- We found out that a dash is 3 times as long as a dot, and the interval is the same length as a dot
- We found out that you need a short delay at the end of each letter (3 dots long) and a longer one at the end of each word (7 dots long)
- We made functions for dot(), dash(), and letters such as S and O
- We looked up Morse Code for the other letters, and wrote functions for them
- We added a variable so we could control the speed of the flashes
Here is one version of the final Arduino program. Note that it is incomplete, it just has a few of the letters of the alphabet.
// Code by Michael from CoderDojo Athenry.
// A program to display messages in Morse Code by flashing an LED.
// This is not complete - just some examples.
int interval = 300; // this controls the speed of messages in milliseconds
void setup() {
// Set up the LED as an output pin. The built-in LED is represented by LED_BUILTIN.
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
// Keep repeating our message over and over.
A(); // Morse code for a letter
B();
S();
endword(); // At the end of each word there is an extra delay
}
void dot() {
digitalWrite(LED_BUILTIN, HIGH); // send 5 volts
delay(interval);
digitalWrite(LED_BUILTIN, LOW); // send 0 volts
delay(interval);
}
void dash() {
digitalWrite(LED_BUILTIN, HIGH); // send 5 volts
delay(3 * interval);
digitalWrite(LED_BUILTIN, LOW); // send 0 volts
delay(interval);
}
void endword() {
digitalWrite(LED_BUILTIN, LOW); // send 0 volts
delay(4 * interval);
}
void endletter() {
digitalWrite(LED_BUILTIN, LOW); // send 0 volts
delay(2 * interval);
}
void A() {
dot();
dash();
endletter();
}
void B() {
dash();
dot();
dot();
dot();
endletter();
}
void S() {
dot();
dot();
dot();
endletter();
}
void O() {
dash();
dash();
dash();
endletter();
}