Stap 14: De code
Code:
variabele controles
int BenOn = 0;
int lightOnED = 0;
int lightOnEL = 0;
int lightOnPA = 0;
int lightOnPA2 = 0;
int buttonStateED = 0;
int lastButtonStateED = 0;
int buttonStateEL = 0;
int lastButtonStateEL = 0;
int pressurePA = 0;
int lastPressurePA = 0;
output pinnen
int lightningBolt = 3;
int lightBulbEddison = 4;
int bridgeLights = 5;
int buildingLights = 6;
int ferrisWheelLights = 7;
int benFrankHair = 8;
input pinnen
int eddisonScene = 12;
int benScene = 11;
int parisScene = 1;
VOID Setup {}
Initialiseer de digitale pin als uitgang.
instellen van alle uitgangen
Serial.begin(9600);
pinMode(lightningBolt,OUTPUT);
pinMode(lightBulbEddison,OUTPUT);
pinMode(bridgeLights,OUTPUT);
pinMode(buildingLights,OUTPUT);
pinMode(ferrisWheelLights,OUTPUT);
pinMode(benFrankHair,OUTPUT);
pinMode(eddisonScene,INPUT);
pinMode(benScene,INPUT);
}
void loop {}
Lees alle ingangen
buttonStateED = digitalRead(eddisonScene);
buttonStateEL = digitalRead(benScene);
pressurePA = analogRead(parisScene);
controleren als scène ben ingeschakeld
Als (buttonStateEL! = lastButtonStateEL) {}
if(buttonStateEL == low) {}
Serial.Print ("buttonStateEL pressed\n");
if(BenOn==1) {}
BenOn = 0;
}
anders if(lightOnEL==0) {}
lightOnEL = 1;
}
}
}
lastButtonStateEL = buttonStateEL;
Controleer of eddison knop ingedrukt
Als (buttonStateED! = lastButtonStateED) {}
Als (buttonStateED == LOW) {}
Serial.Print ("buttonStateED pressed\n");
lightOnED =! lightOnED;
}
}
lastButtonStateED = buttonStateED;
/*Serial.Print ("laatste druk:");
Serial.Print(lastPressurePA);
Serial.Print("\n");
Serial.Print ("druk:");
Serial.Print(pressurePA);
Serial.Print("\n"); * /
Druk op Parijs kracht sensor weerstand controleren
if(lastPressurePA==0) {}
Als (pressurePA > 1) {}
if(lightOnPA2 ==1) {}
lightOnPA2 = 0;
}
anders if(lightOnPA ==0) {}
lightOnPA = 1;
}
Serial.Print("pressed\n");
}
}
lastPressurePA = pressurePA;
if(lightOnPA==1) {}
lichten van elk gebied van Parijs sequentieel inschakelen
digitalWrite(bridgeLights,LOW);
delay(2000);
digitalWrite(buildingLights,HIGH);
delay(2000);
digitalWrite(ferrisWheelLights,LOW);
lightOnPA = 0;
lightOnPA2 = 1;
}
anders if(lightOnPA2==1)
{
lichten op houden nadat sequentieel ingeschakeld
digitalWrite(bridgeLights,LOW);
digitalWrite(buildingLights,HIGH);
digitalWrite(ferrisWheelLights,LOW);
}
anders
{
anders zwenking zij vandoor
digitalWrite(bridgeLights,HIGH);
digitalWrite(buildingLights,HIGH);
digitalWrite(ferrisWheelLights,HIGH);
}
if(lightOnED == 1) {}
inschakelen van eddison de gloeilamp
digitalWrite(lightBulbEddison,HIGH);
}
else {}
zwenking vandoor eddison de gloeilamp
digitalWrite(lightBulbEddison,LOW);
}
controleren of lighning bout op?
if(lightOnEL == 1) {}
Als op de BLIKSEMSCHICHT
digitalWrite(lightningBolt,HIGH);
delay(300);
digitalWrite(lightningBolt,LOW);
delay(400);
digitalWrite(lightningBolt,HIGH);
delay(300);
digitalWrite(lightningBolt,LOW);
delay(300);
digitalWrite(lightningBolt,HIGH);
delay(300);
digitalWrite(lightningBolt,LOW);
lightOnEL = 0;
BenOn = 1;
}
anders if(BenOn==1) {}
Bens haar opdagen na blikseminslag
digitalWrite(benFrankHair,LOW);
}
else {}
anders woordjes gebeurt uitschakelen zowel
digitalWrite(benFrankHair,HIGH);
digitalWrite(lightningBolt,LOW);
}
}