mobileNet/game/分类器/arduino.ino
2025-08-24 11:13:46 +08:00

41 lines
967 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <Servo.h> // 加载舵机库
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);
}
}
}
}