Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions boards/arduino-uno-r3-ch340.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Hanbeon app button-switch firmware for CH340-based Arduino Uno clones.
//
// Reports exactly one "P" per stable press and one "R" per stable release.
// The Mac bridge sends FLASH when Hanbeon advances its scan cursor and OFF
// while the scan is not moving. A physical press keeps the LED on.
// Wiring: button COM -> GND, button NO -> D2, LED -> D9.

const byte buttonPin = 2;
const byte ledPin = 9;
const unsigned long debounceMs = 30;
const unsigned long flashMs = 120;

int lastRawReading = HIGH;
int stableState = HIGH;
unsigned long lastChangeMs = 0;
unsigned long flashUntilMs = 0;
String command;
bool commandHadCarriageReturn = false;

void setup() {
pinMode(buttonPin, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
Serial.begin(115200);
}

void loop() {
readBridgeCommands();

const int rawReading = digitalRead(buttonPin);

if (rawReading != lastRawReading) {
lastChangeMs = millis();
lastRawReading = rawReading;
}

if (millis() - lastChangeMs >= debounceMs && rawReading != stableState) {
stableState = rawReading;
Serial.println(stableState == LOW ? "P" : "R");
}

const bool buttonPressed = stableState == LOW;
const bool flashing = millis() < flashUntilMs;
digitalWrite(ledPin, buttonPressed || flashing ? HIGH : LOW);
}

void readBridgeCommands() {
while (Serial.available() > 0) {
const char next = static_cast<char>(Serial.read());
if (next == '\n') {
if (command == "HELLO" && !commandHadCarriageReturn) {
Serial.print("HANBEON_UNO_V1\n");
} else if (command == "FLASH") {
flashUntilMs = millis() + flashMs;
} else if (command == "OFF") {
flashUntilMs = 0;
}
command = "";
commandHadCarriageReturn = false;
} else if (next == '\r') {
commandHadCarriageReturn = true;
} else {
command += next;
}
}
}
40 changes: 40 additions & 0 deletions sources/boards/arduino-uno-r3-ch340.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"schemaVersion": 1,
"id": "arduino.uno-r3-ch340",
"name": "Arduino Uno R3 호환 보드 (CH340)",
"sketch": {
"path": "boards/arduino-uno-r3-ch340.ino",
"fqbn": "arduino:avr:uno"
},
"detect": {
"usb": [
{
"vid": "1a86",
"pid": "7523",
"confidence": "ambiguous"
},
{
"vid": "1a86",
"pid": "7522",
"confidence": "ambiguous"
},
{
"vid": "1a86",
"pid": "5523",
"confidence": "ambiguous"
}
]
},
"wiring": [
{
"from": "D2",
"to": "순간 누름 스위치 NO 단자",
"note": "스위치 COM 단자는 GND에 연결"
},
{
"from": "D9",
"to": "LED 양극",
"note": "220~330Ω 직렬 저항을 사용하고 LED 음극은 GND에 연결"
}
]
}