Building this circuit was pretty straightforward, I just followed the instructions in the SIK Guide. Instead of using the SIK Guide example code I decided to modify my morse code program from the previous circuit. My modified morse code program allows the potentiometer to affect the timing of the morse code message, so that adjusting the potentiometer causes the message to be displayed at a faster or slower rate. Here is the program:
# define LED_PIN 12 // Pin number attached to LED.
void setup() {
// put your setup code here, to run once:
pinMode(LED_PIN, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
letterA();
longSpace();
letterD();
longSpace();
letterA();
longSpace();
letterM();
longerSpace();
}
int ditDuration(){
//read the position of the pot
return analogRead(A0);
}
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(ditDuration()); // The duration of a dit is based on the position of the potentiometer.
}
void dah(){
digitalWrite(LED_PIN, HIGH); // Turn on the LED.
delay(3*ditDuration()); // The duration of a dah is 3 times that of a dit.
}
void space(){
digitalWrite(LED_PIN, LOW); // Turn off the LED.
delay(ditDuration()); // The duration of a space is equal to that of a dit.
}
void longSpace(){
digitalWrite(LED_PIN, LOW); // Turn off the LED.
delay(3*ditDuration()); // The duration is 3 times that of a dit, used between characters.
}
void longerSpace(){
digitalWrite(LED_PIN, LOW); // Turn off the LED.
delay(7*ditDuration()); // The duration is 7 times that of a dit, used between words.
}
The main changes from the original morse code program are that ditDuration() was added to return the value from the potentiometer, and multiples of that value were used to adjust the delay time in dit(), dah(), space(), longSpace(), and longerSpace().
Here is a video of the morse code potentiometer program in action:
I did have one difficulty while writing the program. Initially, I only checked the value of the potentiometer once inside loop(). The issue with this is that the rate of blinking of the LED would not change until loop() had restarted. This meant that when I turned the potentiometer on the breadboard, the rate of blinking would not change until the current morse code message was completely finished. To make the LED more immediately responsive to the potentiometer, I put analogRead(A0) inside ditDuration(), and then called ditDuration() in dit(), dah(), space(), longSpace(), and longerSpace(). This means that the potentiometer value is read every time the LED turns on or off, so that when I turn the knob I just have to wait until the LED turns on or off again to see the change in the rate of blinking.
The Landing is a social site for Athabasca University staff, students and invited guests. It is a space where they can share, communicate and connect with anyone or everyone.
Unless you are logged in, you will only be able to see the fraction of posts on the site that have been made public. Right now you are not logged in.
If you have an Athabasca University login ID, use your standard username and password to access this site.
We welcome comments on public posts from members of the public. Please note, however, that all comments made on public posts must be moderated by their owners before they become visible on the site. The owner of the post (and no one else) has to do that.
If you want the full range of features and you have a login ID, log in using the links at the top of the page or at https://landing.athabascau.ca/login (logins are secure and encrypted)
Posts made here are the responsibility of their owners and may not reflect the views of Athabasca University.