机动战士高达ol吧 关注:49,962贴子:1,372,655
  • 1回复贴,共1
C:\Users\sunji\AppData\Local\Temp\ccHwe1qb.ltrans0.ltrans.o: In function `main':
C:\Users\sunji\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino/main.cpp:43: undefined reference to `setup'
collect2.exe: error: ld returned 1 exit status
exit status 1
Compilation error: exit status 1


IP属地:广东1楼2024-12-21 17:13回复
    #include <Servo.h>
    // 创建舵机对象
    Servo myServo;
    // 定义电位器和舵机引脚
    const int potPin = A0; // 电位器连接的模拟引脚
    const int servoPin = 9; // 舵机连接的数字引脚
    void setup() {
    myServo.attach(servoPin); // 初始化舵机
    }
    void loop() {
    int potValue = analogRead(potPin); // 读取电位器的值(0-1023)
    int angle = map(potValue, 0, 1023, 0, 180); // 将电位器值映射到舵机角度(0-180)
    myServo.write(angle); // 设置舵机角度
    delay(15); // 短暂延迟,确保舵机平稳运动
    }


    IP属地:广东来自iPhone客户端2楼2024-12-21 17:18
    回复