아두이노 레오나르도 r3 코딩 전환 변환 파이썬 전자 신호 기계적 신호
Arduino IDE
ㅡ>>>>>https://www.arduino.cc/en/software/
아두이노 레오나르도 r3
#include "Keyboard.h"
struct MacroStep {
char key;
float min Delay;
float maxDelay;
bool active;
};
MacroStep steps[10];
bool isRunning = false;
void setup() {
Serial.begin(9600);
Keyboard.begin();
}
void loop() {
// 1. PC로부터 데이터 수신 (간단한 파싱 로직)
if (Serial.available() > 0) {
String command = Serial.readStringUntil('\n');
if (command.startsWith("START")) {
isRunning = true;
} else if (command.startsWith("STOP")) {
isRunning = false;
Keyboard.releaseAll();
} else if (command.startsWith("SET")) {
// 데이터 형식: SET,인덱스,키값,최소지연,최대지연,활성화여부
// 예: SET,0,a,1.1,7.0,1
parseCommand(command);
}
}
// 2. 매크로 실행 루프
if (isRunning) {
for (int i = 0; i < 10; i++) {
if (!isRunning) break;
if (steps[i].active && steps[i].key != 0) {
Keyboard.press(steps[i].key);
delay(50); // 짧은 누름 유지
Keyboard.release(steps[i].key);
long waitTime = random(steps[i].minDelay * 1000, steps[i].maxDelay * 1000);
delay(waitTime);
}
}
}
}
void parseCommand(String msg) {
int firstIdx = msg.indexOf(',');
int secondIdx = msg.indexOf(',', firstIdx + 1);
// ... (상세 파싱 로직 생략 - 통신 규약에 맞게 구현 가능)
}


