4. Embedded programming¶
This week I worked on embedded programming using arduino
Research¶
we researched as a group few arduino micro controllers learning about their capacities and their builtin features alongside the pins which are ports some for input some for output for various things such as power, signals..and etc, and we got to know Programming languages used in them.
We learned about Arduino IDE which is c++ based and circuit python.
testing arduinos¶
I worked on Arduino MKR WIFI 1010 micro controller to try simple things on the embedded led light output, the first one was to make the light brightness fade in and out, the second one was making the light gives output in morse code corresponding with the input text i give.
installing python¶
1- Download and install mu edittor
2- download these two files
3- place those 2 files in the chip file
4- open the mu editor make a code then save it in the cip file in the place of the code file with the same name as it
ps: if the chip file is not showing press this button in the red circle twice
Code Example¶
Fading light code in Arduino IDE
int ledPin = LED_BUILTIN; // LED pin
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
// Increasing brightness
for (int brightness = 0; brightness <= 255; brightness++) {
analogWrite(ledPin, brightness);
delay(5);
}
// Decreasing brightness
for (int brightness = 255; brightness >= 0; brightness--) {
analogWrite(ledPin, brightness);
delay(5);
}
}
morse code in Arduino IDE
int ledPin = LED_BUILTIN; // LED pin
// Morse code mapping
const char* morseCode[] = {
".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..",
".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.",
"...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."
};
const int dotDuration = 200; // Duration of a dot in milliseconds
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
if (Serial.available()) {
String text = Serial.readStringUntil('\n'); // Read the incoming text from Serial
text.toLowerCase(); // Convert the text to lowercase
for (int i = 0; i < text.length(); i++) {
char c = text.charAt(i);
if (c >= 'a' && c <= 'z') {
int index = c - 'a';
playMorseCode(morseCode[index]);
}
else if (c == ' ') {
delay(dotDuration * 3); // Space between words
}
}
}
}
void playMorseCode(const char* morse) {
for (int i = 0; i < strlen(morse); i++) {
char c = morse[i];
if (c == '.') {
digitalWrite(ledPin, HIGH);
delay(dotDuration);
digitalWrite(ledPin, LOW);
delay(dotDuration);
}
else if (c == '-') {
digitalWrite(ledPin, HIGH);
delay(dotDuration * 3);
digitalWrite(ledPin, LOW);
delay(dotDuration);
}
}
delay(dotDuration * 2); // Space between letters
}
SOS morse message in Python
import time
import board
import digitalio
from time import sleep
led = digitalio.DigitalInOut(board.D6)
led.direction = digitalio.Direction.OUTPUT
while True:
led.value = True
sleep(1)
led.value = False
sleep(0.5)
led.value = True
sleep(1)
led.value = False
sleep(0.5)
led.value = True
sleep(1)
led.value = False
sleep(0.5)
led.value = True
sleep(2)
led.value = False
sleep(0.5)
led.value = True
sleep(2)
led.value = False
sleep(0.5)
led.value = True
sleep(2)
led.value = False
sleep(0.5)
led.value = True
sleep(1)
led.value = False
sleep(0.5)
led.value = True
sleep(1)
led.value = False
sleep(0.5)
led.value = True
sleep(1)
led.value = False
sleep(3)
Gallery¶
files¶
click to download my car model
Video¶
From Vimeo¶
Sound Waves from George Gally (Radarboy) on Vimeo.