Stap 16: De code
opmerkingen uitleggen wat de meeste alles doet.
De code:
#include < AFMotor.h >
#include < Servo.h >
Foto weerstand pin
int LDR = 0;
motoren
Servo myServo;
AF_DCMotor centralMotor (2, MOTOR12_64KHZ);
AF_DCMotor artMotor(1,MOTOR12_64KHZ);
Servo pin en lichte variabele
int servoPin = 9;
int lightread = 0;
Acryl besturingselementen
//----------------------------------------------------------
VOID AcrylicClockWise()
{
centralMotor.run(FORWARD);
delay(300);
}
VOID AcrylicCounterClockWise()
{
centralMotor.run(BACKWARD);
}
VOID AcrylicStop()
{
centralMotor.run(RELEASE);
}
//----------------------------------------------------------
Artemis besturingselementen
//----------------------------------------------------------
VOID ArtemisStart()
{
artMotor.run(FORWARD);
}
VOID ArtemisStop()
{
artMotor.run(RELEASE);
}
//----------------------------------------------------------
Apollo besturingselementen
//----------------------------------------------------------
VOID ApolloClockWise()
{
myServo.attach(servoPin);
myServo.write(97);
}
VOID ApolloCounterClockWise()
{
myServo.attach(servoPin);
myServo.write(112);
}
VOID ApolloStop()
{
myServo.detach();
}
//-----------------------------------------------------------
VOID Setup
{
instellen van de pens-modus in te voeren
pinMode (LDR, INPUT);
Serial.begin(9600);
motor snelheid instellen
centralMotor.setSpeed(40);
artMotor.setSpeed(40);
}
void loop
{
Draai de acryl de allertijden
AcrylicClockWise();
stoppen met regelmatige tussenpozen
AcrylicStop();
Lees het licht in de variabele
lightread = analogRead(LDR);
als licht is veel stel apollo te draaien en stoppen van artemis
if(lightread<700)
{
centralMotor.setSpeed(40);
ArtemisStop();
ApolloClockWise();
}
anders
{
anders instellen artemis te gaan en apollo te stoppen
centralMotor.setSpeed(40);
ApolloStop();
ArtemisStart();
}
}