试试这样写,我没验证、[mw_shl_code=arduino,true]#define HIGH_state 1
#define LOW_long 2
#define LOW_state 3
int ASignal = A0;
int x=6;
int state = HIGH_state;
boolean flag =false;
void setup()
{
pinMode(ASignal, INPUT);
Serial.begin(9600);
pinMode(x,OUTPUT);
digitalWrite(x,HIGH);
}
void loop()
{
if(analogRead(ASignal)>700)
{
flag=false;
}
else
{
flag=true;
}
switch(state)
{
case HIGH_state:
if(flag==false)
{
digitalWrite(x,LOW);
state==LOW_state;
}
break;
case LOW_long:
if(flag==true)
{
digitalWrite(x,HIGH);
state==HIGH_state;
}
break;
case LOW_state:
delay(1000);
digitalWrite(x,HIGH);
state==LOW_long;
default :break;
}
} [/mw_shl_code]
|