From 1e29344455bf9ae8e5fd3dec4c84be817bc3ab8d Mon Sep 17 00:00:00 2001 From: 51hhh Date: Sun, 24 Aug 2025 11:13:46 +0800 Subject: [PATCH] =?UTF-8?q?[CF]=E6=B7=BB=E5=8A=A0=E4=B8=8B=E4=BD=8D?= =?UTF-8?q?=E6=9C=BA=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game/分类器/arduino.ino | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 game/分类器/arduino.ino diff --git a/game/分类器/arduino.ino b/game/分类器/arduino.ino new file mode 100644 index 0000000..696a39d --- /dev/null +++ b/game/分类器/arduino.ino @@ -0,0 +1,40 @@ +#include // 加载舵机库 +Servo myservo; // 创建舵机对象 + +void setup() { + myservo.attach(9); // 将舵机信号线连接到数字9引脚 + Serial.begin(9600);// 初始化串口,设置波特率为9600 + // myservo.write(0); +} + +void loop() { + for (int pos = 80; pos <= 100; pos += 1) { // 从0°转到180° + myservo.write(pos); // 设置舵机角度 + delay(15); // 等待15毫秒 + } + for (int pos = 100; pos >= 80; pos -= 1) { + myservo.write(pos); // 设置舵机角度 + delay(15); // 等待15毫秒 + } + + if (Serial.available() > 0) { + // 读取数据 + char received = Serial.read(); + // 输出数据 + Serial.print("Received: "); + Serial.println(received); + + if (received == '1'){ + myservo.write(0); + for ( int i = 0;i <= 100;i += 1){ + delay(10); + } + } + if (received == '2') { + myservo.write(180); + for ( int i = 0;i <= 100;i += 1){ + delay(10); + } + } + } +}