Aaron Dennis
Created September 3, 2024

Developing a low-cost accessibility module for public transp

Transforming lives by developing advanced assistive technologies to improve accessibility for individuals with visual impairments.

12
Developing a low-cost accessibility module for public transp

Things used in this project

Story

Read more

Code

Innovative Assistive Technologies for Visual Impairment

C/C++
Description of the Code
Libraries Used: The code includes the Wire library for I2C communication and the LiquidCrystal_I2C library for controlling the LCD display.
LCD Initialization: The LCD is initialized with an I2C address (0x27) and configured to display 16 characters across 2 lines.
Setup Function: In the setup() function, the LCD is initialized, the backlight is turned on, and a welcome message is displayed.
Loop Function: The loop() function is where the main functionality resides. It can be expanded to include reading input from buttons or sensors to adjust settings based on user preferences.

Button Input: The code uses two buttons connected to digital pins (2 and 3) to allow users to increase or decrease the text size displayed on the LCD. The buttons are set to use the internal pull-up resistors, meaning they will read HIGH when not pressed and LOW when pressed.
Text Size Variable: The textSize variable keeps track of the current text size. It starts at 1 and can be increased or decreased based on user input.
Display Update Function: The updateDisplay() function clears the LCD and updates it with the current text size, ensuring that the user always sees the latest information.
Debouncing: A delay of 300 milliseconds is included after each button press to prevent multiple readings from a single press, which is known as "button bouncing."
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// Initialize the LCD with I2C address 0x27, 16 columns and 2 rows
LiquidCrystal_I2C lcd(0x27, 16, 2);

// Define pin numbers for buttons
const int buttonIncrease = 2; // Pin for increasing text size
const int buttonDecrease = 3; // Pin for decreasing text size

// Variable to store text size
int textSize = 1; // Default text size

void setup() {
  // Initialize the LCD
  lcd.begin();
  lcd.backlight();
  
  // Print the welcome message
  lcd.setCursor(0, 0);
  lcd.print("Welcome!");
  lcd.setCursor(0, 1);
  lcd.print("Text Size: ");
  lcd.print(textSize);

  // Set button pins as input
  pinMode(buttonIncrease, INPUT_PULLUP);
  pinMode(buttonDecrease, INPUT_PULLUP);
}

void loop() {
  // Check if the increase button is pressed
  if (digitalRead(buttonIncrease) == LOW) {
    textSize++; // Increase text size
    updateDisplay(); // Update the display with new text size
    delay(300); // Debounce delay
  }

  // Check if the decrease button is pressed
  if (digitalRead(buttonDecrease) == LOW) {
    if (textSize > 1) { // Prevent text size from going below 1
      textSize--; // Decrease text size
      updateDisplay(); // Update the display with new text size
      delay(300); // Debounce delay
    }
  }
}

// Function to update the display with the current text size
void updateDisplay() {
  lcd.clear(); // Clear the LCD
  lcd.setCursor(0, 0);
  lcd.print("Welcome!");
  lcd.setCursor(0, 1);
  lcd.print("Text Size: ");
  lcd.print(textSize);
}

Credits

Aaron Dennis

Aaron Dennis

1 project • 1 follower

Comments