主要问题是光敏电阻输出低电平0,不倒转,左下方引脚2也没反应,当光敏电阻输出高电平,左下方限位引脚1闭合电机停转,没有什么问题,就是倒转不行
#include <Servo.h>
#include <dht11.h>
dht11 DHT11;
#define DHT11PIN 3
Servo servo_pin_4;
Servo servo_pin_7;
int photocellPin = 11; // 光敏电阻接口
int LightState;
int state1=1;
int state2=1;
int pin1=1;
int pin2=2;
void setup()
{
servo_pin_4.attach(4);
servo_pin_7.attach(7);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
}
void loop()
{
state1 = digitalRead(pin1);
state2 = digitalRead(pin2);
int chk = DHT11.read(DHT11PIN);
if(DHT11.temperature<20){
servo_pin_4.write( 0 );
servo_pin_7.write( 0);}
else {
servo_pin_4.write( 90 );
servo_pin_7.write( 90 );
}
LightState = digitalRead(photocellPin);
if (LightState==1)
{
digitalWrite(6,LOW);
digitalWrite(5,HIGH);
if (state1==0)
{
digitalWrite(5,LOW);
}
}
else if(LightState==0)
{
digitalWrite(5,LOW);
digitalWrite(6,HIGH);
if (state2==0)
{
digitalWrite(6,LOW);
digitalWrite(5,LOW);
}
}
}
|