Professional Documents
Culture Documents
Codigo Puente Arduino
Codigo Puente Arduino
int switchstate2 = 0;
//sensores de luz.
// variable to hold sensor value
int sensorValue1;
int sensorValue2;
// variable to calibrate low value
int sensorLow = 1023;
// variable to calibrate high value
int sensorHigh = 0;
// LED pin
//servomotor
// include the servo library
#include <Servo.h>
//servomotor
Servo myServo; // create a servo object
void setup() {
// put your setup code here, to run once:
pinMode(10, INPUT);
pinMode(11, INPUT);
//Sensores luz
// Make the LED pin an output and turn it on
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
void loop() {
// put your main code here, to run repeatedly:
{
//Sensores.
//read the input from A0 and store it in a variable
sensorValue1 = analogRead(A1);
//read the input from A0 and store it in a variable
sensorValue2 = analogRead(A2);
}
switchstate1 = digitalRead(11);
switchstate2 = digitalRead(10);
if (switchstate1==LOW) {
if (sensorValue1<700) {
// set the servo position
digitalWrite(4, HIGH); // turn the yellow LED on pin 4 on
digitalWrite(2, LOW); // turn the green LED on pin 2 off
delay(3000);
myServo.write(60);
digitalWrite(3, HIGH); // turn the red LED on pin 3 on
}
if (sensorValue2<700) {
// set the servo position
delay(3000);
myServo.write(0);
digitalWrite(4, HIGH); // turn the yellow LED on pin 4 on
digitalWrite(3, LOW); // turn the red LED on pin 3 off
delay(3000);
digitalWrite(4, LOW); // turn the yellow LED on pin 4 off
digitalWrite(2, HIGH); // turn the green LED on pin 2 on
delay(15);
}
}
else {
if (switchstate2==HIGH){
myServo.write(60);
digitalWrite(3, HIGH); // turn the red LED on pin 3 on
digitalWrite(2, LOW); // turn the green LED on pin 2 off
delay(15);
}
else {
myServo.write(0);
digitalWrite(4, HIGH); // turn the yellow LED on pin 4 on
digitalWrite(3, LOW); // turn the red LED on pin 3 off
delay(3000);
digitalWrite(4, LOW); // turn the yellow LED on pin 4 off
digitalWrite(2, HIGH); // turn the green LED on pin 2 on
delay(15);
}
}
}