Paso 7: Código completo
#include < Servo.h >#include < stdio.h >
Servo bigServo;
Servo smallServo;
int SmallServoPin = A13;
int BigServoPin = A15;
int pos = 0;
Activación de int = 0;
int moveBeds = 0;
int lightChange = 0;
int val = 0;
int cuenta;
int tiempo;
int BlackGreenPin = 24;
int RedBluePin = 22;
int lightThreshold = 500;
PASOS de int = 70;
int stepDelay = 100;
void setup()
{
Serial.Begin(9600);
bigServo.attach(BigServoPin);
smallServo.attach(SmallServoPin);
pos = 110;
cuenta = 0;
controles de PIN
pinMode (BlackGreenPin, salida);
pinMode (RedBluePin, salida);
pinMode (A2, entrada);
}
void loop()
{
Serial.println(serial.List());
Serial.println();
Val = analogRead(A2);
Serial.Print ("valor de luz =");
Serial.println(Val);
if(Val > lightThreshold)
{
Activación = 1;
if(lightChange == 1)
{
moveBeds = 1;
lightChange = 0;
}
}
otra cosa
{
Activación = 0;
if(lightChange == 0)
{
moveBeds = 1;
lightChange = 1;
}
}
if(wakeUp == 0)
{
para (pos, pos > = 110; pos-= 1)
{
bigServo.write(pos);
smallServo.write(pos-70);
Delay(15);
}
if(moveBeds == 1)
{
moveBeds = 0;
Move(0);
}
}
if(wakeUp == 1)
{
if(moveBeds == 1)
{
moveBeds = 0;
Move(1);
}
para (pos, pos < 179; pos += 1)
{
bigServo.write(pos);
smallServo.write(pos-70);
Delay(15);
}
}
Delay(1000);
}
void mover (int a)
{
Si (a == 1)
{
para (int i = 0; i < pasos; i ++)
{
digitalWrite (BlackGreenPin, alto);
Delay(stepDelay);
digitalWrite (RedBluePin, bajo);
Delay(stepDelay);
digitalWrite (BlackGreenPin, bajo);
Delay(stepDelay);
digitalWrite (RedBluePin, alto);
Delay(stepDelay);
}
}
else if (hasta == 0)
{
para (int i = 0; i < pasos; i ++)
{
digitalWrite (BlackGreenPin, alto);
Delay(stepDelay);
digitalWrite (RedBluePin, alto);
Delay(stepDelay);
digitalWrite (BlackGreenPin, bajo);
Delay(stepDelay);
digitalWrite (RedBluePin, bajo);
Delay(stepDelay);
}
}
otra cosa
{
Serial.Print ("Error en la función de movimiento. Valor inesperado - ");
Serial.println(up);
}
}