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 "CircleClock.h"
#include "RTC.h"
#include <Wire.h>
#include "TouchScreen.h"
#include "Menu.h"
#include "Alarm.h"
#include "AddAlarm.h"

// 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;


// 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
};

Screen currentScreen = CLOCK;

void setup() {

  // Configure the backlight pin as an output.
  pinMode(PIN_BL, OUTPUT);

  // Turn the backlight on.
  digitalWrite(PIN_BL, HIGH);

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

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

  Wire.begin(5, 6);
  Serial.begin(115200);

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

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


void loop() {
  /*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; i++) {
      data[i] = Wire.read();
    }

    if (data[0] == 1) {

      Serial.print("Touch: ");

      for (int i = 0; i < 6; i++) {
        Serial.print(data[i]);
        Serial.print(" ");
      }

      Serial.println();
    }
  }

  delay(100);*/


  int hours;
  int minutes;
  int seconds;

  getTime(hours, minutes, seconds);

  /*int touchXtest;
  int touchYtest;

  if (getTouch(touchXtest, touchYtest)) {

    Serial.print("Touch: X = ");
    Serial.print(touchXtest);

    Serial.print(" | Y = ");
    Serial.println(touchYtest);
  }*/

  int touchX;
  int touchY;

  static bool touching = false;
  static int startY = 0;
  static int lastTouchY = 0;
  static int startX = 0;
  static int lastTouchX = 0;
  static int lastScrollY = 0;

  // торкаємося екрану
  if (getTouch(touchX, touchY)) {

  

More projects by melimelum586