led — Arduino Uno simulation

An interactive Arduino Uno circuit simulation you can run free in your browser on Velxio, by 709394.

Components

Sketch code

/*
  硬件连接:
  - LED: 13(红), 12(黄), 11(绿), 10(蓝) 各串联470Ω到GND
  - 按键: A0接10kΩ上拉到5V,开关接GND
  - OLED: VIN→5V, GND→GND, DATA→A4 (SDA), CLK→A5 (SCL)
*/

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

// LED引脚
#define RED_PIN    13
#define YELLOW_PIN 12
#define GREEN_PIN  11
#define BLUE_PIN   10
#define BUTTON_PIN A0

// 状态枚举
enum State {
  FLOW,
  YELLOW_3S,
  RED_HOLD,
  YELLOW_5S,
  GREEN_HOLD,
  TIMEOUT_RED_BLINK,
  TIMEOUT_GREEN_BLINK,
  TIMEOUT_YELLOW_BLINK
};

State currentState = FLOW;

unsigned long lastFlowTime = 0;
const unsigned long FLOW_INTERVAL = 250;
int flowIndex = 0;
unsigned long stateStartTime = 0;

bool lastPressedState = false;
const int PRESS_THRESHOLD = 100;

unsigned long lastDisplayUpdate = 0;
const unsigned long DISPLAY_UPDATE_INTERVAL = 100;

bool flowShowText = true;
unsigned long lastBlinkTime = 0;
const unsigned long BLINK_INTERVAL = 500;

// ---------- 20x32 中文字模(完整数据) ----------
static const unsigned char PROGMEM chineseFont32[6][96] = {
  // "过" (0)
  {
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x10,0x03,0x00,0x10,0x03,0x00,0x18,
    0x03,0x00,0x18,0x03,0x00,0x1C,0x03,0x00,0x0D,0xFF,0xE0,0x09,0xFF,0xE0,0x00,0x03,
    0x00,0x00,0x03,0x00,0x00,0x43,0x00,0x7C,0xC3,0x00,0x7C,0xC3,0x00,0x7C,0x43,0x00,
    0x0C,0x63,0x00,0x0C,0x63,0x00,0x0C,0x63,0x00,0x0C,0x03,0x00,0x0C,0x03,0x00,0x0C,
    0x03,0x00,0x0C,0x03,0x00,0x0C,0x03,0x00,0x0C,0x0E,0x00,0x1C,0x0E,0x00,0x1E,0x08,
    0x00,0x37,0x80,0x00,0x63,0xFF,0xE0,0x61,0xFF,0xE0,0x00,0x3F,0xE0,0x00,0x00,0x00
  },
  // "马" (1)
  {
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xFE,0x00,0x1F,
    0xFE,0x00,0x00,0x06,0x00,0x00,0x06,0x00,0x06,0x06,0x00,0x06,0x06,0x00,0x06,0x06,
    0x00,0x06,0x06,0x00,0x06,0x06,0x00,0x04,0x04,0x00,0x04,0x04,0x00,0x04,0x04,0x00,
    0x07,0xFF,0xC0,0x07,0xFF,0xC0,0x00,0x00,0xC0,0x00,0x00,0xC0,0x00,0x00,0xC0,0x00,
    0x00,0xC0,0x3F,0xFE,0xC0,0x3F,0xFE,0xC0,0x00,0x00,0xC0,0x00,0x00,0x80,0x00,0x00,
    0x80,0x00,0x01,0x80,0x00,0x0F,0x80,0x00,0x0F,0x00,0x00,0x0E,0x00,0x00,0x00,0x00
  },
  // "路" (2)
  {
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x18,0x00,0x3F,0x18,0x00,0x3F,
    0x1F,0xC0,0x31,0x3F,0xC0,0x31,0x30,0x80,0x31,0x31,0x80,0x31,0x71,0x80,0x31,0x59,
    0x00,0x3F,0x4B,0x00,0x3F,0x0E,0x00,0x04,0x06,0x00,0x04,0x0F,0x00,0x04,0x1F,0x80,
    0x34,0x39,0xC0,0x34,0xF0,0xE0,0x37,0x40,0x60,0x37,0x3F,0x80,0x34,0x3F,0x80,0x34,
    0x20,0x80,0x34,0x20,0x80,0x34,0x20,0x80,0x34,0xA0,0x80,0x37,0xA0,0x80,0x3F,0x3F,
    0x80,0x7C,0x3F,0x80,0x70,0x20,0x80,0x40,0x20,0x80,0x00,0x20,0x80,0x00,0x00,0x00
  },
  // "请" (3)
  {
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x10,0x0C,0x00,0x30,0x0C,0x00,0x19,
    0xFF,0xC0,0x0D,0xFF,0xC0,0x0C,0x0C,0x00,0x00,0xFF,0xC0,0x00,0xFF,0xC0,0x00,0x0C,
    0x00,0x00,0x0C,0x00,0x79,0xFF,0xE0,0x79,0xFF,0xE0,0x18,0x00,0x0

More projects by 709394