HTMAA 2024 - Week 3

Previous: Laser Cutting Home Next: 3D Printing and Scanning

Week 3: Embedded Programming

This week, we delved into embedded programming to interact with local input/output devices and explore communication using wired and wireless connections. Below is an example demonstrating how we used a microcontroller to display information on an LCD screen and toggle between modes using a button.


#include 
#include 

#define BTN_PIN 5
#define TFT_DC 2
#define TFT_CS 15
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);

bool lastButtonState = HIGH;
bool currentMessageInfo = true;

void displayMessage(const char* message, uint16_t color) {
    tft.fillScreen(ILI9341_BLACK);
    tft.setCursor(0, 0);
    tft.setTextColor(color);
    tft.setTextSize(2);
    tft.println(message);
}

void displayFireArt() {
    tft.fillScreen(ILI9341_BLACK);
    tft.setCursor(0, 0);
    tft.setTextColor(ILI9341_RED);
    tft.setTextSize(1);
    tft.println("  🔥 Fire Animation 🔥 ");
}

void setup() {
    pinMode(BTN_PIN, INPUT_PULLUP);
    tft.begin();
    tft.setRotation(1);
    displayMessage("Welcome to Embedded Programming", ILI9341_WHITE);
}

void loop() {
    bool buttonState = digitalRead(BTN_PIN);
    if (buttonState != lastButtonState) {
        lastButtonState = buttonState;
        if (buttonState == LOW) {
            if (currentMessageInfo) {
                displayFireArt();
                currentMessageInfo = false;
            }
        } else {
            if (!currentMessageInfo) {
                displayMessage("Welcome to Embedded Programming", ILI9341_WHITE);
                currentMessageInfo = true;
            }
        }
    }
    delay(50);
}
        

Assignment: