Individual assignment:
* read a microcontroller data sheet
* program your board to do something with as many different programming languages and programming environments as possible
Group assignment:
* compare the performance and development workflows for other architectures
const int buttonPin = 3; //Pin for the button
const int LEDPin = 2; //Pin for the LED
const int LEDPin2 = 4; //Pin for the LED2 (added line)
void setup()
{
pinMode(buttonPin, INPUT); //setting the input PIN
pinMode(LEDPin, OUTPUT); //setting the output PIN
pinMode(LEDPin2, OUTPUT); //(added line)
Serial.begin(9600); // Serial console setup
}
Next thing would be a defining the Morse Code for "HELLO WORLD", so:
if (digitalRead(buttonPin) == HIGH) //checking the state of the button
{
So after the state of the button goes HIGH meaning that it was pressed and blinking code is executed.
const int buttonPin = 3; //Pin for the button
const int LEDPin = 2; //Pin for the LED
const int LEDPin2 = 4; //Pin for the LED2
void setup()
{
pinMode(buttonPin, INPUT); //setting the input PIN
pinMode(LEDPin, OUTPUT); //setting the output PIN
pinMode(LEDPin2, OUTPUT);
Serial.begin(9600); // Serial console setup
}
void loop()
{
if (digitalRead(buttonPin) == HIGH) //checking the state of the button
{
Serial.println("Start H"); // H is 4 shorts
digitalWrite(LEDPin, HIGH); //setting the LED on
Serial.println("*");
delay(500); //0.5s delay
digitalWrite(LEDPin, LOW); //setting the LED off
delay(500); //0.5s delay
digitalWrite(LEDPin, HIGH); //setting the LED on
Serial.println("*");
delay(500); //0.5s delay
digitalWrite(LEDPin, LOW); //setting the LED off
delay(500); //0.5s delay
digitalWrite(LEDPin, HIGH); //setting the LED on
Serial.println("*");
delay(500); //0.5s delay
digitalWrite(LEDPin, LOW); //setting the LED off
delay(500); //0.5s delay
digitalWrite(LEDPin, HIGH); //setting the LED on
Serial.println("*");
delay(500); //0.5s delay
digitalWrite(LEDPin, LOW); //setting the LED off
Serial.println("Ends H");
delay(500); //0.5s delay
Serial.println("Start E"); //E is 1 short
digitalWrite(LEDPin, HIGH); //setting the LED on
Serial.println("*");
delay(500); //0.5s delay
digitalWrite(LEDPin, LOW); //setting the LED off
Serial.println("Ends E");
delay(500); //0.5s delay
Serial.println("Start L"); //L is 1 short , 1 long, 2 short
digitalWrite(LEDPin, HIGH); //setting the LED on
Serial.println("*");
delay(500); //0.5s delay
digitalWrite(LEDPin, LOW); //setting the LED off
delay(500); //0.5s delay
digitalWrite(LEDPin, HIGH); //setting the LED on
digitalWrite(LEDPin2, HIGH); //setting the LED2 on
Serial.println("-");
delay(500); //0.5s delay
digitalWrite(LEDPin, LOW); //setting the LED off
digitalWrite(LEDPin2, LOW); //setting the LED2 off
delay(500); //0.5s delay
digitalWrite(LEDPin, HIGH); //setting the LED on
Serial.println("*");
delay(500); //0.5s delay
digitalWrite(LEDPin, LOW); //setting the LED off
delay(500); //0.5s delay
digitalWrite(LEDPin, HIGH); //setting the LED on
Serial.println("*");
delay(500); //0.5s delay
digitalWrite(LEDPin, LOW); //setting the LED off
delay(500); //0.5s delay
Serial.println("Ends L");
Serial.println("Start L"); //L is 1 short , 1 long, 2 short
digitalWrite(LEDPin, HIGH); //setting the LED on
Serial.println("*");
delay(500); //0.5s delay
digitalWrite(LEDPin, LOW); //setting the LED off
delay(500); //0.5s delay
digitalWrite(LEDPin, HIGH); //setting the LED on
digitalWrite(LEDPin2, HIGH); //setting the LED2 on
Serial.println("-");
delay(500); //0.5s delay
digitalWrite(LEDPin, LOW); //setting the LED off
digitalWrite(LEDPin2, LOW); //setting the LED2 off
delay(500); //0.5s delay
digitalWrite(LEDPin, HIGH); //setting the LED on
Serial.println("*");
delay(500); //0.5s delay
digitalWrite(LEDPin, LOW); //setting the LED off
delay(500); //0.5s delay
digitalWrite(LEDPin, HIGH); //setting the LED on
Serial.println("*");
delay(500); //0.5s delay
digitalWrite(LEDPin, LOW); //setting the LED off
delay(500); //0.5s delay
Serial.println("Ends L");
Serial.println("Starts O"); //O is 3 long
digitalWrite(LEDPin, HIGH); //setting the LED on
digitalWrite(LEDPin2, HIGH); //setting the LED2 on
Serial.println("-");
delay(500); //0.5s delay
digitalWrite(LEDPin, LOW); //setting the LED off
digitalWrite(LEDPin2, LOW); //setting the LED2 off
delay(500); //0.5s delay
digitalWrite(LEDPin, HIGH); //setting the LED on
digitalWrite(LEDPin2, HIGH); //setting the LED2 on
Serial.println("-");
delay(500); //0.5s delay
digitalWrite(LEDPin, LOW); //setting the LED off
digitalWrite(LEDPin2, LOW); //setting the LED2 off
delay(500); //0.5s delay
digitalWrite(LEDPin, HIGH); //setting the LED on
digitalWrite(LEDPin2, HIGH); //setting the LED2 on
Serial.println("-");
delay(500); //0.5s delay
digitalWrite(LEDPin, LOW); //setting the LED off
digitalWrite(LEDPin2, LOW); //setting the LED2 off
delay(500); //0.5s delay
Serial.println("Ends O");
Serial.println("Longer Delay between words");
delay(500); //0.5s delay
Serial.println("Starts W"); //W is 1 short, 2 long
digitalWrite(LEDPin, HIGH); //setting the LED on
Serial.println("*");
delay(500); //0.5s delay
digitalWrite(LEDPin, LOW); //setting the LED off
delay(500); //0.5s delay
digitalWrite(LEDPin, HIGH); //setting the LED on
digitalWrite(LEDPin2, HIGH); //setting the LED2 on
Serial.println("-");
delay(500); //0.5s delay
digitalWrite(LEDPin, LOW); //setting the LED off
digitalWrite(LEDPin2, LOW); //setting the LED2 off
delay(500); //0.5s delay
digitalWrite(LEDPin, HIGH); //setting the LED on
digitalWrite(LEDPin2, HIGH); //setting the LED2 on
Serial.println("-");
delay(500); //0.5s delay
digitalWrite(LEDPin, LOW); //setting the LED off
digitalWrite(LEDPin2, LOW); //setting the LED2 off
delay(500); //0.5s delay
Serial.println("Ends W");
Serial.println("Starts O"); //O is 3 long
digitalWrite(LEDPin, HIGH); //setting the LED on
digitalWrite(LEDPin2, HIGH); //setting the LED2 on
Serial.println("-");
delay(500); //0.5s delay
digitalWrite(LEDPin, LOW); //setting the LED off
digitalWrite(LEDPin2, LOW); //setting the LED2 off
delay(500); //0.5s delay
digitalWrite(LEDPin, HIGH); //setting the LED on
digitalWrite(LEDPin2, HIGH); //setting the LED2 on
Serial.println("-");
delay(500); //0.5s delay
digitalWrite(LEDPin, LOW); //setting the LED off
digitalWrite(LEDPin2, LOW); //setting the LED2 off
delay(500); //0.5s delay
digitalWrite(LEDPin, HIGH); //setting the LED on
digitalWrite(LEDPin2, HIGH); //setting the LED2 on
Serial.println("-");
delay(500); //0.5s delay
digitalWrite(LEDPin, LOW); //setting the LED off
digitalWrite(LEDPin2, LOW); //setting the LED2 off
delay(500); //0.5s delay
Serial.println("Ends O");
Serial.println("Start R");
digitalWrite(LEDPin, HIGH); //setting the LED on
Serial.println("*");
delay(500); //0.5s delay
digitalWrite(LEDPin, LOW); //setting the LED off
delay(500); //0.5s delay
digitalWrite(LEDPin, HIGH); //setting the LED on
digitalWrite(LEDPin2, HIGH); //setting the LED2 on
Serial.println("-");
delay(500); //0.5s delay
digitalWrite(LEDPin, LOW); //setting the LED off
digitalWrite(LEDPin2, LOW); //setting the LED2 off
delay(500); //0.5s delay
digitalWrite(LEDPin, HIGH); //setting the LED on
Serial.println("*");
delay(500); //0.5s delay
digitalWrite(LEDPin, LOW); //setting the LED off
delay(500); //0.5s delay
Serial.println("Start L"); //L is 1 short , 1 long, 2 short
digitalWrite(LEDPin, HIGH); //setting the LED on
Serial.println("*");
delay(500); //0.5s delay
digitalWrite(LEDPin, LOW); //setting the LED off
delay(500); //0.5s delay
digitalWrite(LEDPin, HIGH); //setting the LED on
digitalWrite(LEDPin2, HIGH); //setting the LED2 on
Serial.println("-");
delay(500); //0.5s delay
digitalWrite(LEDPin, LOW); //setting the LED off
digitalWrite(LEDPin2, LOW); //setting the LED2 off
delay(500); //0.5s delay
digitalWrite(LEDPin, HIGH); //setting the LED on
Serial.println("*");
delay(500); //0.5s delay
digitalWrite(LEDPin, LOW); //setting the LED off
delay(500); //0.5s delay
digitalWrite(LEDPin, HIGH); //setting the LED on
Serial.println("*");
delay(500); //0.5s delay
digitalWrite(LEDPin, LOW); //setting the LED off
delay(500); //0.5s delay
Serial.println("Ends L");
Serial.println("Starts D");
digitalWrite(LEDPin, HIGH); //setting the LED on
digitalWrite(LEDPin2, HIGH); //setting the LED2 on
Serial.println("-");
delay(500); //0.5s delay
digitalWrite(LEDPin, LOW); //setting the LED off
digitalWrite(LEDPin2, LOW); //setting the LED2 off
delay(500); //0.5s delay
digitalWrite(LEDPin, HIGH); //setting the LED on
Serial.println("*");
delay(500); //0.5s delay
digitalWrite(LEDPin, LOW); //setting the LED off
delay(500); //0.5s delay
digitalWrite(LEDPin, HIGH); //setting the LED on
Serial.println("*");
delay(500); //0.5s delay
digitalWrite(LEDPin, LOW); //setting the LED off
delay(500); //0.5s delay
Serial.println("Ends D");
Serial.println("Ends Hello World sequence");
}
}
Video of code and board operation: nano blink.py
. Command nano
run the text editor and blink.py
is a name of the new file that we crate.
from gpiozero import LED, Button
from time import sleep
from signal import pause
def morse_signal(signal):
if signal == "short":
led.on()
sleep(.5)
led.off()
sleep(.5)
if signal == "long":
led.on()
led1.on()
sleep(.5)
led.off()
led1.off()
sleep(.5)
if signal == "brake":
sleep(1)
def morse_letter(letter):
if letter == "H":
print("Start of H")
morse_signal("short")
morse_signal("short")
morse_signal("short")
morse_signal("short")
print("End of H")
if letter == "E":
print("Start of E")
morse_signal("short")
print("End of E")
if letter == "L":
print("Start of L")
morse_signal("short")
morse_signal("long")
morse_signal("short")
morse_signal("short")
print("End of L")
if letter == "O":
print("Start of O")
morse_signal("long")
morse_signal("long")
morse_signal("long")
print("End of O")
if letter == "W":
print("Start of W")
morse_signal("short")
morse_signal("long")
morse_signal("long")
print("End of W")
if letter == "R":
print("Start of R")
morse_signal("short")
morse_signal("long")
morse_signal("short")
print("End of R")
if letter == "D":
print("Start of D")
morse_signal("long")
morse_signal("short")
morse_signal("short")
print("End of D")
led = LED(4)
led1 = LED(17)
button = Button(2)
button.wait_for_press()
morse_letter("H")
morse_letter("E")
morse_letter("L")
morse_letter("L")
morse_letter("O")
morse_signal("break")
morse_letter("W")
morse_letter("O")
morse_letter("R")
morse_letter("L")
morse_letter("D")
pause()