Skip to content
Snippets Groups Projects
Commit d140e59f authored by Ethan Walters's avatar Ethan Walters
Browse files

Added code source information comments to LCD and Arduino code

parent 934f32f2
No related branches found
No related tags found
No related merge requests found
// --------------------------------------------------------------------------
// Arduino sketch for controlling a servo motor and reading button presses
// The very core concepts of this sketch were taken from Lab1_code2
// https://gitlab.com/IOTGarage/iot-lab-book/-/tree/070cf41b33cffdc1f1f90f6a42e1e16215db24be/LAB%2001%20-%20Micro-Controller%20Programming/Lab1_code2
// However two-way serial communication was added to allow the servo to be controlled from Node-Red, and the buttons to send messages to Node-Red
// --------------------------------------------------------------------------
// Include the Servo library
#include <Servo.h>
......@@ -17,7 +24,10 @@ Servo myservo;
void setup() {
Serial.begin(9600); // Start serial communication at 9600 baud
// Initialise button pins as input
// Initialise button pins as input_pullup
// This means the button will read LOW when pressed and HIGH when not pressed
// This change was made from the original code, which used INPUT
// This is because, through research, we found input_pullup is more reliable for buttons
pinMode(BUTTON1_PIN, INPUT_PULLUP);
pinMode(BUTTON2_PIN, INPUT_PULLUP);
......@@ -33,7 +43,7 @@ void loop()
Serial.println("Received: " + command); // Serial output for debugging
// Check if the command starts with "SERVO " (e.g., "SERVO 90")
// Check if the command starts with "SERVO " (e.g. "SERVO 90")
// This is the expected format for controlling the servo
if (command.startsWith("SERVO ")) {
int angle = command.substring(6).toInt(); // Extract angle value
......
// --------------------------------------------------------------------------
// Arduino sketch for controlling a servo motor and reading button presses
// The very core concepts of this sketch were taken from Lab1_code1
// https://gitlab.com/IOTGarage/iot-lab-book/-/blob/070cf41b33cffdc1f1f90f6a42e1e16215db24be/LAB%2001%20-%20Micro-Controller%20Programming/Lab1_code1
// However two-way serial communication was added to allow the servo to be controlled from Node-Red, and the PIR motion sensor to send messages to Node-Red
// This motion sensor also has a toggle function, allowing it to be turned on and off from Node-Red, allowing for timely servo control when needed
// --------------------------------------------------------------------------
// Include the Servo library
#include <Servo.h>
......
# --------------------------------------------------------------------------
# This code is adapted from dht11_lcd5.py
# https://gitlab.com/IOTGarage/iot-lab-book/-/blob/070cf41b33cffdc1f1f90f6a42e1e16215db24be/LAB%2002%20-%20Single-board%20Computer%20Programming/dht11_lcd5.py
# I have modified the code to take RGB values and text input from arguments rather than from the dht11 sensor.
# I also added error handling for the RGB values and text input, such as clamping the RGB values to the range of 0-255 and checking if the text input is empty.
# This means the code can be used to display any text and RGB values on the LCD based on parameters passed by Node-Red, with appropriate debugging capabilities.
# --------------------------------------------------------------------------
#!/usr/bin/env python3
import time
import sys
......@@ -32,9 +40,12 @@ def setText(text):
if not text.strip():
print("Error: Text input cannot be empty.")
sys.exit(1)
# Clear display
textCommand(0x01)
time.sleep(0.05)
# Display on, no cursor
textCommand(0x08 | 0x04)
# 2-line display mode
textCommand(0x28)
time.sleep(0.05)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment