[AppleScript] syntaxhighlighter_viewsource syntaxhighlighter_copycode
//当按键1按下
if(val8==LOW)
{
distance = sr04_read();
Serial.print(".....distance is:");
Serial.print(distance);
Serial.print("cm");
Serial.println();
delay(1000);
if(distance<=10.0)
{
for(j=0;j<1;j++)
{
for(i=4;i<8;i++)
{
digitalWrite(i,HIGH);
delay(200);
digitalWrite(i,LOW);
delay(200);
}
break;
}
}
if(distance<=100.0&&distance>10.0)
{for(j=0;j<1;j++)
{for(i=7;i>=4;i--)
{
digitalWrite(i,HIGH);
delay(200);
digitalWrite(i,LOW);
delay(200);
}
break;
}
}
if(distance>100.0)
{ for(j=0;j<1;j++)
{
digitalWrite(5,HIGH);
digitalWrite(6,HIGH);
delay(200);
digitalWrite(4,HIGH);
digitalWrite(7,HIGH);
delay(200);
digitalWrite(4,LOW);
digitalWrite(7,LOW);
delay(200);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
break;
}
}
}
//当按键2按下
if(val9==LOW)
{
distance = (sr04_read())/100.0;
Serial.print(".....distance is:");
Serial.print(distance);
Serial.print("m");
Serial.println();
delay(1000);
if(distance<=0.1)
{
for(j=0;j<1;j++)
{for(i=4;i<8;i++)
{
digitalWrite(i,HIGH);
delay(200);
digitalWrite(i,LOW);
delay(200);
}
break;
}
}
if(distance<=1&&distance>0.1)
{for(j=0;j<1;j++)
{for(i=7;i>=4;i--)
{
digitalWrite(i,HIGH);
delay(200);
digitalWrite(i,LOW);
delay(200);
}
break;
}
}
if(distance>1)
{ for(j=0;j<1;j++)
{digitalWrite(5,HIGH);
digitalWrite(6,HIGH);
delay(200);
digitalWrite(4,HIGH);
digitalWrite(7,HIGH);
delay(200);
digitalWrite(4,LOW);
digitalWrite(7,LOW);
delay(200);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
break;
}
}
}
//当按键3按下
if(val10==LOW)
{
distance = sr04_read()/2.54;
Serial.print(".....distance is:");
Serial.print(distance);
Serial.print("in");
Serial.println();
delay(1000);
if(distance<=(10.0/2.45))
{for(j=0;j<1;j++)
{for(i=4;i<8;i++)
{
digitalWrite(i,HIGH);
delay(200);
digitalWrite(i,LOW);
delay(200);
}
break;
}
}
if(distance<=(100.0/2.45)&&distance>(10.0/2.45))
{for(j=0;j<1;j++)
{for(i=7;i>=4;i--)
{
digitalWrite(i,HIGH);
delay(200);
digitalWrite(i,LOW);
delay(200);
}
break;
}
}
if(distance>(100.0/2.45))
{ for(j=0;j<1;j++)
{digitalWrite(5,HIGH);
digitalWrite(6,HIGH);
delay(200);
digitalWrite(4,HIGH);
digitalWrite(7,HIGH);
delay(200);
digitalWrite(4,LOW);
digitalWrite(7,LOW);
delay(200);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
break;
}
}
}