int nInputLine=8; //设置遥控信号读取引脚
int nNormal=6; //左红右绿尾部常亮灯
int nLandingLight=7; //着陆灯
unsigned int nCount=0; //计数器
int nStatus=1; //状态
struct tag_WingLight{
int nPort=2;
int nOffset=0;
int nOff=148;
int nOn=1;
int nOff2=10;
int nOn2=1;
}nWingLight;//机翼频闪灯
struct tag_TailLight{
int nPort=4;
int nOffset=70;
int nOff=139;
int nOn=1;
}nTailLight;//尾部频闪灯
struct tag_UpDown{
int nPort=5;
int nOffset=0;
int nOff=150;
int nOn=1;
}nUpDown;//上下防撞灯
void setup() {
// put your setup code here, to run once:
pinMode(nInputLine, INPUT); //设置遥控信号读取引脚
pinMode(nWingLight.nPort, OUTPUT); //机翼频闪灯
pinMode(nTailLight.nPort, OUTPUT); //尾部频闪灯
pinMode(nUpDown.nPort, OUTPUT); //上下防撞灯
pinMode(nNormal, OUTPUT); //左红右绿尾部常亮灯
pinMode(nLandingLight, OUTPUT); //着陆灯
digitalWrite(nNormal,HIGH);
digitalWrite(nLandingLight,HIGH);
}
void loop() {
// put your main code here, to run repeatedly:
/*if(nCount==(nCount/10*10)){
if(pulseIn(nInputLine, HIGH)>1200){
if(nStatus==1){
digitalWrite(nWingLight.nPort,LOW);
digitalWrite(nTailLight.nPort,LOW);
digitalWrite(nUpDown.nPort,LOW);
digitalWrite(nNormal,LOW);
digitalWrite(nLandingLight,LOW);
nStatus=0;
}
}
else{
nStatus=1;
}
}*/
if(nStatus){
int nTmp=(nCount+nWingLight.nOffset)%(nWingLight.nOff+nWingLight.nOn+nWingLight.nOff2+nWingLight.nOn2);
int nO1=nWingLight.nOff;
int nO2=nWingLight.nOff+nWingLight.nOn;
int nO3=nWingLight.nOff+nWingLight.nOn+nWingLight.nOff2;
if(nTmp==0)
digitalWrite(nWingLight.nPort,LOW);
if(nTmp==nWingLight.nOff)
digitalWrite(nWingLight.nPort,HIGH);
if(nTmp==nWingLight.nOff+nWingLight.nOn)
digitalWrite(nWingLight.nPort,LOW);
if(nTmp==nWingLight.nOff+nWingLight.nOn+nWingLight.nOff2)
digitalWrite(nWingLight.nPort,HIGH);
nTmp=(nCount+nTailLight.nOffset)%(nTailLight.nOff+nTailLight.nOn);
if(nTmp==nTailLight.nOff){
digitalWrite(nTailLight.nPort,HIGH);
}
else{
if(nTmp==0)
digitalWrite(nTailLight.nPort,LOW);
}
nTmp=(nCount+nUpDown.nOffset)%(nUpDown.nOff+nUpDown.nOn);
if(nTmp==nUpDown.nOff){
digitalWrite(nUpDown.nPort,HIGH);
}
else{
if(nTmp==0)
digitalWrite(nUpDown.nPort,LOW);
}
}
nCount++;
delay(10);
}
|