#include <Arduino.h>
#include "HttpClient.h"
//https://app.beeceptor.com/console/wokwidemo
const char* ssid = "Wokwi-GUEST";
const char* password = "";
const char* url = "https://wokwidemo.free.beeceptor.com/api/users";
HttpClient httpClient(ssid, password);
const char* centerName = "Test Center";
const char* centerId = "65cef46f0b3aeb76fd38dbfb";
const char* name;
const char* weight;
bool recyclable = false;
void postData() {
httpClient.postData(url, centerName, centerId, "Copper wires", "2.4kg", recyclable);
}
#include <Adafruit_FT6206.h>
#include <TFT_eSPI.h>
#include <SPI.h>
TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h
Adafruit_FT6206 ts = Adafruit_FT6206(); // Initialize the touch screen
#include "colors.h"
#include "free_fonts.h"
#include "WasteList.h"
WasteList wasteList(tft, ts);
#include "HX711Helper.h"
#define LOADCELL_DOUT_PIN 13
#define LOADCELL_SCK_PIN 12
const long LOADCELL_DIVIDER = 420;
HX711Helper scale(tft, ts);
#include "TouchButton.h"
TouchButton calibrateButton(tft, ts, 5, 65, 115, 50, SLATE_BLUE);
TouchButton nameButton (tft, ts, 5, 125, 115, 50, YELLOW_GREEN);
TouchButton typeButton (tft, ts, 5, 185, 135, 50, YELLOW_GREEN);
TouchButton submitButton (tft, ts, 205, 185, 110, 50, FIREBRICK);
void calibrateButtonPressed() {
Serial.println("Calibrate scale...");
scale.tare();
setHomeScreen();
}
void calibrateButtonReleased() {
Serial.println("Scale calibrated!");
}
void nameButtonPressed() {
wasteList.displayPage();
Serial.println("Select waste name.");
setHomeScreen();
}
void nameButtonReleased() {
Serial.println("Waste name selected!");
}
void typeButtonPressed() {
Serial.println("Changing type...");
}
void typeButtonReleased() {
tft.setTextSize(2);
if(recyclable) {
typeButton.setText("Non\nRecyclable", WHITE, 2);
typeButton.drawButton();
recyclable = false;
} else {
typeButton.setText(" \nRecyclable", WHITE, 2);
typeButton.drawButton();
recyclable = true;
}
Serial.println("Type changed!");
}
void submitButtonPressed() {
Serial.println("Submit details?");
loadScreen("Submitting Details!");
postData();
setHomeScreen();
}
void submitButtonReleased() {
Serial.println("Details submitted!");
}
void loadScreen(const char* str) {
tft.fillScreen(BLACK);
tft.setTextSize(3);
tft.setTextColor(YELLOW_GREEN);
tft.setCursor(6, 6);
tft.print("Baeru Smart Scale");
tft.setTextColor(WHITE);
tft.setCursor(5, 5);
tft.print("Baeru Smart Scale");
tft.setCursor(0, (tft.height() / 2));
tft.setTextSize(2);
tft.println(str);
tft.println("Please wait...");
}
void setHomeScreen() {
tft.fillScreen(BLACK);
tft.setTextSize(3);
tft.setTextColor(YELLOW_GREEN);
tft.setCursor(6, 6);
tft.print("Baeru Smart Scale");
tft.setTextColor(WHITE);
tft.setCursor(5, 5);
tft.print("Baeru Smart Scale");
tft.setCursor(5, 5 + tft.fontHeight());
tft.setTextSize(2);
tft.print(centerName);
calibrateButton.setText("Calibrate\nScale", WHITE, 2);
calibrateButton.setPressCallback(&calibrateButtonPressed);
calibrateButton.setReleaseCallback(&calibrateButtonReleased);
calibrateButton.drawButton();
nameButton.setText("Waste\nName", WHITE, 2);
nameButton.setPressCallback(&nameButtonPressed);
nameButton.setReleaseCallback(&nameButtonReleased);
nameButton.drawButton();
if(recyclable) {
typeButton.setText(" \nRecyclable", WHITE, 2);
} else {
typeButton.setText("Non\nRecyclable", WHITE, 2);
}
typeButton.setPressCallback(&typeButtonPressed);
typeButton.setReleaseCallback(&typeButtonReleased);
typeButton.drawButton();
submitButton.setText("Submit\nDetails", WHITE, 2);
submitButton.setPressCallback(&submitButtonPressed);
submitButton.setReleaseCallback(&submitButtonReleased);
submitButton.drawButton();
}
void setup() {
Serial.begin(9600);
tft.begin();
ts.begin();
tft.setRotation(1); // Landscape orientation
tft.fillScreen(TFT_BLACK);
tft.setTextSize(2);
tft.setTextColor(TFT_WHITE);
loadScreen("Connecting to WIFi!");
httpClient.connect();
Serial.println("...");
setHomeScreen();
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
scale.setDivider(LOADCELL_DIVIDER);
}
void loop() {
scale.getWeight();
typeButton.update();
nameButton.update();
calibrateButton.update();
submitButton.update();
}