Skip to content

Commit

Permalink
Merge pull request #30 from aleemont1/alessandro
Browse files Browse the repository at this point in the history
LCD prints and fix
  • Loading branch information
aleemont1 authored Dec 4, 2023
2 parents d3b1499 + 3de6c8d commit 3cc3eb9
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 6 deletions.
1 change: 1 addition & 0 deletions smart_bridge/src/components/api/LCD.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class LCD {
*/
LCD(int address, int columns, int rows);
void write(const char* string, int start_col, int start_rows);
void clear();
protected:
LiquidCrystal_I2C lcd;
};
Expand Down
13 changes: 10 additions & 3 deletions smart_bridge/src/components/impl/LCD.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
#include "../api/LCD.h"
#include "Arduino.h"

LCD::LCD(int address, int columns, int rows) : lcd(address, columns, rows) {
LCD::LCD(int address, int columns, int rows) : lcd(address, columns, rows)
{
lcd.init();
lcd.backlight();
lcd.clear();
}

void LCD::write(const char* string, int start_col, int start_rows) {
void LCD::clear()
{
lcd.clear();
}

void LCD::write(const char *string, int start_col, int start_rows)
{
Serial.println("LCD::Sto scrivendo sul display" + String(string));
lcd.clear();
lcd.setCursor(start_col, start_rows);
lcd.print(string);
}
4 changes: 4 additions & 0 deletions smart_bridge/src/tasks/CheckInTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ void CheckInTask::tick()
{

case STARTED:
lcd->clear(); // Clear the LCD
lcd->write("WELCOME TO THE", 0, 0);
lcd->write("SMART WASHING", 0, 1);
L1->switchOn(); // Turn on L1
#ifdef __LOG
Serial.println("CheckInTask::Turned on L1");
#endif
this->resetTime(); // Reset the elapsed time
this->setState(WAITING); // Set the state to WAITING
break;
case WAITING:
Expand Down
6 changes: 5 additions & 1 deletion smart_bridge/src/tasks/CheckInTask.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#ifndef __CHECK_IN_TASK__
#define __CHECK_IN_TASK__

#include "config/config.h"

#include "kernel/DependantTaskWithState.h"
#include "components/api/Led.h"
#include "config/config.h"
#include "components/api/LCD.h"
#include "components/api/ServoImpl.h"

/**
Expand All @@ -19,6 +21,7 @@ class CheckInTask : public DependantTaskWithState
{
this->L1 = new Led(L1_PIN);
this->L2 = new Led(L2_PIN);
this->lcd = new LCD(0x27, 16, 2);
this->gate = new ServoImpl(SERVO_PIN);
this->init();
this->setState(STARTED);
Expand All @@ -34,6 +37,7 @@ class CheckInTask : public DependantTaskWithState
};
Led *L1;
Led *L2;
LCD *lcd;
ServoImpl *gate;
};

Expand Down
2 changes: 2 additions & 0 deletions smart_bridge/src/tasks/TransitTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ void TransitTask::tick()
switch (this->getState())
{
case READING_DISTANCE:
this->lcd->write("Proceed to the", 0, 0);
this->lcd->write("washing area!", 0, 1);
this->L2->switchOn();
this->distance = sonar->detectDistance();
#ifdef __LOG
Expand Down
5 changes: 4 additions & 1 deletion smart_bridge/src/tasks/TransitTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
#include "kernel/DependantTaskWithState.h"
#include "BlinkTask.h"
#include "config/config.h"
#include "components/api/Sonar.h"
#include "components/api/Led.h"
#include "components/api/LCD.h"
#include "components/api/ServoImpl.h"
#include "components/api/Sonar.h"
/**
* @class TransitTask
* @brief This task reads the distance of the car while entering the washing area.
Expand All @@ -26,6 +27,7 @@ class TransitTask : public DependantTaskWithState
Serial.println("TransitTask created");
this->sonar = new Sonar(SONAR_TRIG_PIN, SONAR_ECHO_PIN, SONAR_MAX_TIME);
this->L2 = new Led(L2_PIN);
this->lcd = new LCD(0x27, 16, 2);
// TODO: FIX SERVO.
this->gate = new ServoImpl(SERVO_PIN);
this->blinkTask = blinkTask;
Expand All @@ -44,6 +46,7 @@ class TransitTask : public DependantTaskWithState
CHECKING_DISTANCE
};
Led *L2;
LCD *lcd;
Sonar *sonar;
ServoImpl *gate;
float distance;
Expand Down
11 changes: 10 additions & 1 deletion smart_bridge/src/tasks/WaitForClickTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,21 @@ void WaitForClickTask::tick()
{
if (this->getDependency(0) != nullptr)
{
//Serial.println("WaitForClickTask::getDependency(0) != nullptr");
if (this->getDependency(0)->isCompleted())
{
this->lcd->write("Press START to", 0, 0);
this->lcd->write("begin washing", 0, 1);
#ifdef __LOG
Serial.println("WaitForClickTask::Waiting for START click");
#endif
this->start->sync();
if (this->start->isPressed())
{
#ifdef __LOG
Serial.println("WaitForClickTask::START pressed");
#endif
this->lcd->clear();
this->lcd->write("Starting to wash", 0, 0);
this->setCompleted();
}
}
Expand Down
2 changes: 2 additions & 0 deletions smart_bridge/src/tasks/WaitForClickTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class WaitForClickTask : public DependantTask
WaitForClickTask() : DependantTask()
{
this->start = new Button(BUTTON_PIN);
this->lcd = new LCD(0x27, 16, 2);
this->init();
Serial.println("WaitForClickTask created");
};
Expand All @@ -28,5 +29,6 @@ class WaitForClickTask : public DependantTask

private:
Button *start;
LCD *lcd;
};
#endif

0 comments on commit 3cc3eb9

Please sign in to comment.