Práctica 1 Con Arduino
Práctica 1 Con Arduino
void setup() {
pinMode(led, OUTPUT); //Se configura el pin 13 como salida
}
void loop() {
digitalWrite(led, HIGH); // Se enciende el led
delay(1000); // Se espera unos segundos
digitalWrite(led, LOW); // Se apaga el led
delay(1000); // Se espera unos segundos
}
Prctica 2: SEMFORO.
int ledR = 12;
int ledA = 9;
int ledV = 6;
void setup() {
pinMode(ledR, OUTPUT);
pinMode(ledA, OUTPUT);
pinMode(ledV, OUTPUT);
}
void loop() {
digitalWrite(ledR, HIGH); // Semforo en rojo
digitalWrite(ledA, LOW);
digitalWrite(ledV, LOW);
delay(1000);
digitalWrite(ledR, LOW); // semforo en verde
digitalWrite(ledA, LOW);
digitalWrite(ledV, HIGH);
delay(1000);
digitalWrite(ledR, LOW);
digitalWrite(ledA, HIGH);
digitalWrite(ledV, LOW); // semforo en amarillo
delay(1000);
digitalWrite(ledR, LOW); // tiempo de espera todo apagado
digitalWrite(ledA, LOW);
digitalWrite(ledV, LOW);
delay(1000);
}
Prctica 3: ENCENDER LED CON PULSADOR
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
void setup() {
// declare the ledPin as an OUTPUT:
pinMode(ledPin, OUTPUT);
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
digitalWrite(ledPin, HIGH);
// stop the program for <sensorValue> milliseconds:
delay(sensorValue);
// turn the ledPin off:
digitalWrite(ledPin, LOW);
// stop the program for for <sensorValue> milliseconds:
delay(sensorValue);
}
void loop() {
sensorValue = analogRead(sensorPin);
if (sensorValue >200){
digitalWrite(ledPin, LOW);}
else{
digitalWrite(ledPin, HIGH);}
}
Prctica 6: CONTROL DE UN SERVOMOTOR.
#include <Servo.h>
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable pos
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable pos
delay(15); // waits 15ms for the servo to reach the position
}
}