为什么不起作用?

问题描述 投票:0回答:1

嗨,这是个好人,可以用我破碎的arduino代码帮助我。我为四足机器人编写代码。

#include <Servo.h>
int SVal =(Serial.read(A1))
int TVal =(Serial.read(A0))
int FVal =(TVal - FVal)
Servo myservo;  

void setup() {
  Serial.begin(9600);
  myservo.attach(9);  
}

void loop() {
  FVal = map(FVal, 0, 1023, 0, 180);     
  myservo.write(FVal);                  
  delay(15);                          
}
arduino robot dog
1个回答
0
投票

您的Serial.read()开始于您的Serial.begin()设置。将其移入循环。

#include <Servo.h>

Servo myservo;  

void setup() {
  Serial.begin(9600);
  myservo.attach(9);  
}

void loop() {
  int SVal =(Serial.read(A1))
  int TVal =(Serial.read(A0))
  int FVal =(TVal - FVal)
  FVal = map(FVal, 0, 1023, 0, 180);     
  myservo.write(FVal);                  
  delay(15);                          
}
© www.soinside.com 2019 - 2024. All rights reserved.