7374| 3
|
[求助] 光敏电阻控制舵机开关 |
想通过光敏电阻控制舵机的转动 当亮度低于一定值的时候光敏电阻输出高电平 可代码不管打if(val==0)还是if(val==1)都是亮光才会触发舵机 有大佬知道怎么改吗…(T—T)… #include <Servo.h> Servo myservo; int buttonPin=13; int val=0; void setup() { Serial.println("Run control"); myservo.attach(9); Serial.begin(9600); } void loop() { val=digitalRead(buttonPin); if(val=0){ myservo.write(155); delay(1000); myservo.write(60); delay(400); myservo.write(25); delay(800); myservo.write(155); delay(400); } } |
#include <Servo.h> Servo myServo; int photo1 = A0; // LDR int servoPin = 9; // servo pin int val1 = 0; // value of LDR void setup() { Serial.begin(9600); myServo.attach(servoPin); myServo.write(90); pinMode(photo1, INPUT); Serial.println("made by gada888"); } void loop() { delay(500); val1 = analogRead(photo1); Serial.print("Photo1 Value: "); Serial.println(val1); if (val1 >= 800 ) { myServo.write(90); Serial.println("dark"); } else if(val1 < 800) { myServo.write(40); Serial.println("light"); } } 在Buddy+里软件测试通过。没进行硬件测试 |
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed