CIRCUITOS
// C++ code
//
int t = 100; // declare a variable to use for delay
void setup()
{
// setup code that only runs once
// set pins 0-7 as outputs
pinMode(0, OUTPUT);
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
}
void loop()
{
// code that loops forever
// note that each LED requires its own line of code
// turn pin 0 on, others low
digitalWrite(0, HIGH);
digitalWrite(1, LOW);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
delay(t); // Wait for t millisecond(s)
// turn pin 1 on, others low
digitalWrite(0, LOW);
digitalWrite(1, HIGH);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
delay(t); // Wait for t millisecond(s)
// turn pin 2 on, others low
digitalWrite(0, LOW);
digitalWrite(1, LOW);
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
delay(t); // Wait for t millisecond(s)
// turn pin 3 on, others low
digitalWrite(0, LOW);
digitalWrite(1, LOW);
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
delay(t); // Wait for t millisecond(s)
// turn pin 4 on, others low
digitalWrite(0, LOW);
digitalWrite(1, LOW);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
delay(t); // Wait for t millisecond(s)
// turn pin 5 on, others low
digitalWrite(0, LOW);
digitalWrite(1, LOW);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
delay(t); // Wait for t millisecond(s)
// turn pin 6 on, others low
digitalWrite(0, LOW);
digitalWrite(1, LOW);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, HIGH);
digitalWrite(7, LOW);
delay(t); // Wait for t millisecond(s)
// turn pin 7 on, others low
digitalWrite(0, LOW);
digitalWrite(1, LOW);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, HIGH);
delay(t); // Wait for t millisecond(s)
}
const int Trigger = 2; //Pin digital 2 para el Trigger del sensor
const int Echo = 3; //Pin digital 3 para el Echo del sensor
void setup() {
Serial.begin(9600);//iniciailzamos la comunicación
pinMode(Trigger, OUTPUT); //pin como salida
pinMode(Echo, INPUT); //pin como entrada
digitalWrite(Trigger, LOW);//Inicializamos el pin con 0
}
void loop()
{
long t; //timepo que demora en llegar el eco
long d; //distancia en centimetros
digitalWrite(Trigger, HIGH);
delayMicroseconds(10); //Enviamos un pulso de 10us
digitalWrite(Trigger, LOW);
t = pulseIn(Echo, HIGH); //obtenemos el ancho del pulso
d = t/59; //escalamos el tiempo a una distancia en cm
Serial.print("Distancia: ");
Serial.print(d); //Enviamos serialmente el valor de la distancia
Serial.print("cm");
Serial.println();
delay(100); //Hacemos una pausa de 100ms}
int led_red =0; //El LED rojo conecta con el pin 0 del Arduino
int led_yellow =1; //El LED amarillo se conecta con el pin 1 del Arduino
int led_green =2; //El LED verde se conecta con el pin 2 del Arduino
void setup (){
//set up all the LEDs as OUTPUT
pinMode (led_red, OUTPUT);
pinMode (led_yellow, OUTPUT);
pinMode (led_green, OUTPUT);
}
void loop () {
//turn the green LED on and the other LEDs off
digitalWrite (led_red, LOW);
digitalWrite (led_yellow, LOW);
digitalWrite (led_green, HIGH);
delay(2000); //wait 2 seconds
//turn the yellow LED on and the other LEDs off
digitalWrite (led_red, LOW);
digitalWrite (led_yellow, HIGH);
digitalWrite (led_green, LOW);
delay(1000); //wait 1 seconds
//turn the red LED on and the other LEDs off
digitalWrite (led_red, HIGH);
digitalWrite (led_yellow, LOW);
digitalWrite (led_green, LOW);
delay(3000); //wait 3 seconds}
MARIA PAULA MESA BECERRA 9C
Comentarios
Publicar un comentario