wrist_clock — Xiao Esp32 S3 simulation

An interactive Xiao Esp32 S3 circuit simulation you can run free in your browser on Velxio, by melimelum586.

Components

Sketch code

#include <M5GFX.h>
#include <lgfx/v1/panel/Panel_GC9A01.hpp>
#include <math.h>
#include <Adafruit_Sensor.h>

#include "CircleClock.h"
#include "RTC.h"
#include <Wire.h>
#include "TouchScreen.h"
#include "Menu.h"
#include "Alarm.h"
#include "AddAlarm.h"
#include "Timer.h"
#include <Preferences.h>
#include "Brightness.h"

//Adafruit_BME280 bme;
//bool bmeReady = false;

unsigned long lastBmeRead = 0;
const unsigned long bmeInterval = 2000;

// pins
// Display CS pin: XIAO D1 -> GPIO2.
const int PIN_CS = 2;

// Display DC pin: XIAO D3 -> GPIO4.
const int PIN_DC = 4;

// Display backlight pin: XIAO D6 -> GPIO43.
const int PIN_BL = 43;

// SPI clock pin: XIAO D8 -> GPIO7.
const int PIN_SCK = 7;

// SPI MISO pin: XIAO D9 -> GPIO8.
const int PIN_MISO = 8;

// SPI MOSI pin: XIAO D10 -> GPIO9.
const int PIN_MOSI = 9;

Preferences preferences;

int brightness = 250;  // Початкове значення: 180 із 255

// Create our own display class.
class RoundDisplay : public lgfx::LGFX_Device {

  // Create the GC9A01 display panel.
  lgfx::Panel_GC9A01 _gc9a01;

  // Create the SPI communication bus.
  lgfx::Bus_SPI _spi;


public:

  // Configure the display.
  RoundDisplay() {

    auto cfg = _spi.config();
    cfg.spi_host = SPI2_HOST;
    cfg.spi_mode = 0;
    cfg.freq_write = 40000000;
    cfg.pin_sclk = PIN_SCK;
    cfg.pin_mosi = PIN_MOSI;
    cfg.pin_miso = PIN_MISO;
    cfg.pin_dc = PIN_DC;
    _spi.config(cfg);
    _gc9a01.setBus(&_spi);
    auto panel_cfg = _gc9a01.config();
    panel_cfg.pin_cs = PIN_CS;
    panel_cfg.pin_rst = -1;
    panel_cfg.panel_width = 240;
    panel_cfg.panel_height = 240;
    panel_cfg.invert = true;
    _gc9a01.config(panel_cfg);
    setPanel(&_gc9a01);
  }
};


// Create the display object.
RoundDisplay tft;

int lastSecond = -1;
enum Screen {
  CLOCK,
  MENU,
  ALARM,
  ADDALARM,
  TIMER,
  BRIGHTNESS
};

Screen currentScreen = CLOCK;

void setup() {

  Serial.begin(115200);
  
  pinMode(PIN_BL, OUTPUT);

  preferences.begin("clock", false);

  brightness = preferences.getInt("brightness", 250);

  analogWrite(PIN_BL, brightness);

  // Initialize the display.
  tft.init();

  // Set display rotation.
  tft.setRotation(0);

  loadAlarms();

  Wire.begin(5, 6);
  //bmeReady = bme.begin(0x76);
  

  // Check if the touch controller is connected.
  Wire.beginTransmission(0x2E);

  // Draw the clock face.
  drawClockFace(tft);
}


void loop() {
  /*if (bmeReady && millis() - lastBmeRead >= bmeInterval) {
      lastBmeRead = millis();

      float temperature = bme.readTemperature();
      float humidity = bme.readHumidity();
      float pressure = bme.readPressure() / 100.0F;

      Serial.printf("Temperature: %.1f C\n", temperature);
      Serial.printf("Humidity: %.1f %%\n", humidity);
      Serial.printf("Pressure: %.1f hPa\n", pressure);
  }*/
  /*Wire.beginTransmission(0x2E);
  Wire.write(0x00);
  Wire.endTransmission();

  int bytes = Wire.requestFrom(0x2E, 6);

  if (bytes == 6) {

    byte data[6];

    for (int i = 0; i < 6

More projects by melimelum586