ESP32-C6x1 — Esp32 C6 simulation

An interactive Esp32 C6 circuit simulation you can run free in your browser on Velxio, by kshyhoo.

Components

Sketch code

const int NUM_BYTES = 5;
// 74HC165 - PRZYCISKI (BUTTONS)
const int BTN_SL      = 11; // sr16:PL
const int BTN_CK      =  2; // sr16:CP
const int BTN_DI      =  3; // sr16:Q7
// 74HC165 - POTWIERDZENIE (FEEDBACK)
const int FEED_SL     = 13; // sr11:PL
const int FEED_CK     = 12; // sr11:CP
const int FEED_DI     = 18; // sr11:Q7
// 74HC595 - PRZEKAŹNIKI (RELAY)
const int RELAY_CLOCK = 20;
const int RELAY_LATCH = 15;
const int RELAY_DATA  = 19;
// 74HC595 - DIODY LED
const int LED_CLOCK   = 4;
const int LED_LATCH   = 5;
const int LED_DATA    = 0;
//
const int BUZZER_PIN  = 10;
// ===== DEBUG =====
#define DEBUG 1
#define HEARTBEAT_MS 1000   // jak często wypisywać pełny stan, nawet bez zmian
byte buttonData[NUM_BYTES];
byte lastButtonState[NUM_BYTES];
byte relayState[NUM_BYTES];
byte feedbackData[NUM_BYTES];
byte lastPrintedButtons[NUM_BYTES];
byte lastPrintedFeedback[NUM_BYTES];
const int pulseDelay = 5;
unsigned long loopCount = 0;
unsigned long lastHeartbeat = 0;

void printBin(const byte *arr, int n) {
  for (int i = n - 1; i >= 0; i--) {
    for (int b = 7; b >= 0; b--) Serial.print(bitRead(arr[i], b));
    if (i > 0) Serial.print('_');
  }
}

bool changed(const byte *a, const byte *b, int n) {
  for (int i = 0; i < n; i++) if (a[i] != b[i]) return true;
  return false;
}

void setup() {
  Serial.begin(115200);
  unsigned long t0 = millis();
  while (!Serial && millis() - t0 < 2000) delay(10);  // nie blokuj w nieskończoność
  Serial.println("START");
  pinMode(BTN_SL, OUTPUT);
  pinMode(BTN_CK, OUTPUT);
  pinMode(BTN_DI, INPUT);
  pinMode(LED_LATCH, OUTPUT);
  pinMode(LED_CLOCK, OUTPUT);
  pinMode(LED_DATA, OUTPUT);
  pinMode(FEED_SL, OUTPUT);
  pinMode(FEED_CK, OUTPUT);
  pinMode(FEED_DI, INPUT);
  pinMode(RELAY_LATCH, OUTPUT);
  pinMode(RELAY_CLOCK, OUTPUT);
  pinMode(RELAY_DATA, OUTPUT);
  pinMode(BUZZER_PIN, OUTPUT);
  digitalWrite(BUZZER_PIN, LOW);
  digitalWrite(BTN_SL, HIGH);
  digitalWrite(FEED_SL, HIGH);
  digitalWrite(BTN_CK, LOW);
  digitalWrite(FEED_CK, LOW);
  Serial.println("System ESP32-C6");
#if DEBUG
  // Test linii: czy układ 165 w ogóle reaguje na PL/CP
  Serial.print("Q7 przycisków w spoczynku: ");
  Serial.println(digitalRead(BTN_DI));
  Serial.print("Q7 feedbacku w spoczynku: ");
  Serial.println(digitalRead(FEED_DI));
#endif
}

void loop() {
  loopCount++;
  // 1. ODCZYT PRZYCISKÓW
  digitalWrite(BTN_SL, LOW);
  delayMicroseconds(pulseDelay);
  digitalWrite(BTN_SL, HIGH);
  delayMicroseconds(pulseDelay);
  for (int i = NUM_BYTES - 1; i >= 0; i--) {
    for (int j = 0; j < 8; j++) {
      int bit = digitalRead(BTN_DI);
      bitWrite(buttonData[i], j, bit);
      digitalWrite(BTN_CK, HIGH);
      delayMicroseconds(pulseDelay);
      digitalWrite(BTN_CK, LOW);
      delayMicroseconds(pulseDelay);
    }
  }
#if DEBUG
  // 1a. Wypisz surowe bity przycisków, gdy się zmienią
  if (changed(buttonData, lastPrintedButtons, NUM_BYTES)) {
    Serial.print("[BTN raw] ");
    printBin(buttonData, NUM_BYTES);
    Serial.println();
  

More projects by kshyhoo