SPACE INTERFACE (E/S DIGITALES)
- Materiales: swith, led, resistencias de 220 ohm y 10 hohm , una placa arduino y una serie de cables que se muestran en las siguientes imagenes:
(Los colores de las led deben ser rojo, rojo, marrón, plateado y la otra debe ser marrón, negro, naranja y plateado)
- Con todos estos materiales, podemos construir el siguiente montaje introduciendo en arduino (programa parecido a processing) el siguiente código:
/*
Arduino Starter Kit example
Project 2 - Spaceship Interface
This sketch is written to accompany Project 2 in the
Arduino Starter Kit
Parts required:
1 green LED
2 red LEDs
pushbutton
10 kilohm resistor
3 220 ohm resistors
Created 13 September 2012
by Scott Fitzgerald
http://arduino.cc/starterKit
This example code is part of the public domain
*/
// Create a global variable to hold the
// state of the switch. This variable is persistent
// throughout the program. Whenever you refer to
// switchState, you’re talking about the number it holds
int switchstate = 0;
void setup(){
// declare the LED pins as outputs
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
// declare the switch pin as an input
pinMode(2,INPUT);
}
void loop(){
// read the value of the switch
// digitalRead() checks to see if there is voltage
// on the pin or not
switchstate = digitalRead(2);
// if the button is not pressed
// turn on the green LED and off the red LEDs
if (switchstate == LOW) {
digitalWrite(3, HIGH); // turn the green LED on pin 3 on
digitalWrite(4, LOW); // turn the red LED on pin 4 off
digitalWrite(5, LOW); // turn the red LED on pin 5 off
}
// this else is part of the above if() statement.
// if the switch is not LOW (the button is pressed)
// turn off the green LED and blink alternatively the red LEDs
else {
digitalWrite(3, LOW); // turn the green LED on pin 3 off
digitalWrite(4, LOW); // turn the red LED on pin 4 off
digitalWrite(5, HIGH); // turn the red LED on pin 5 on
// wait for a quarter second before changing the light
delay(250);
digitalWrite(4, HIGH); // turn the red LED on pin 4 on
digitalWrite(5, LOW); // turn the red LED on pin 5 off
// wait for a quarter second before changing the light
delay(250);
}
}
Arduino Starter Kit example
Project 2 - Spaceship Interface
This sketch is written to accompany Project 2 in the
Arduino Starter Kit
Parts required:
1 green LED
2 red LEDs
pushbutton
10 kilohm resistor
3 220 ohm resistors
Created 13 September 2012
by Scott Fitzgerald
http://arduino.cc/starterKit
This example code is part of the public domain
*/
// Create a global variable to hold the
// state of the switch. This variable is persistent
// throughout the program. Whenever you refer to
// switchState, you’re talking about the number it holds
int switchstate = 0;
void setup(){
// declare the LED pins as outputs
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
// declare the switch pin as an input
pinMode(2,INPUT);
}
void loop(){
// read the value of the switch
// digitalRead() checks to see if there is voltage
// on the pin or not
switchstate = digitalRead(2);
// if the button is not pressed
// turn on the green LED and off the red LEDs
if (switchstate == LOW) {
digitalWrite(3, HIGH); // turn the green LED on pin 3 on
digitalWrite(4, LOW); // turn the red LED on pin 4 off
digitalWrite(5, LOW); // turn the red LED on pin 5 off
}
// this else is part of the above if() statement.
// if the switch is not LOW (the button is pressed)
// turn off the green LED and blink alternatively the red LEDs
else {
digitalWrite(3, LOW); // turn the green LED on pin 3 off
digitalWrite(4, LOW); // turn the red LED on pin 4 off
digitalWrite(5, HIGH); // turn the red LED on pin 5 on
// wait for a quarter second before changing the light
delay(250);
digitalWrite(4, HIGH); // turn the red LED on pin 4 on
digitalWrite(5, LOW); // turn the red LED on pin 5 off
// wait for a quarter second before changing the light
delay(250);
}
}
Así es como quedaría:
Con este código lo que se hace es una secuencia en la que las bombillas se van encendiendo una después de otra rápidamente.
Seguimos experimentando.
- Con el siguiente código lo que podemos conseguir es lo siguiente: (10/03/15) (De 8.30 a 9:25)
/*
Arduino Starter Kit example
Project 2 - Spaceship Interface
Modificación: video grabado a las nueve y cuarto, dia 10
This sketch is written to accompany Project 2 in the
Arduino Starter Kit
Parts required:
1 green LED
2 red LEDs
pushbutton
10 kilohm resistor
3 220 ohm resistors
Created 13 September 2012
by Scott Fitzgerald
http://arduino.cc/starterKit
This example code is part of the public domain
*/
// Create a global variable to hold the
// state of the switch. This variable is persistent
// throughout the program. Whenever you refer to
// switchState, you’re talking about the number it holds
int switchstate = 0;
void setup(){
// declare the LED pins as outputs
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
// declare the switch pin as an input
pinMode(2,INPUT);
}
void loop(){
// read the value of the switch
// digitalRead() checks to see if there is voltage
// on the pin or not
switchstate = digitalRead(2);
// if the button is not pressed
// blink the red LEDs
if (switchstate == LOW) {
digitalWrite(3, HIGH); // turn the green LED on pin 3 on
digitalWrite(4, LOW); // turn the red LED on pin 4 off
digitalWrite(5, LOW); // turn the red LED on pin 5 off
}
// this else is part of the above if() statement.
// if the switch is not LOW (the button is pressed)
// the code below will run
else {
digitalWrite(4, LOW); // turn the green LED on pin 3 off
digitalWrite(3, LOW); // turn the red LED on pin 4 off
digitalWrite(4, HIGH); // turn the red LED on pin 5 on
// wait for a quarter second before changing the light
delay(250);
digitalWrite(4, HIGH); // turn the red LED on pin 4 on
digitalWrite(5, LOW); // turn the red LED on pin 5 off
// wait for a quarter second before changing the light
delay(250);
}
}
(El trabajo1 solo consiste en que solo se enciendan 2 bombillas de las 3)
(El trabajo2 consiste en que se enciendas las 3 bombillas)
(El trabajo2 consiste en que se enciendas las 3 bombillas)
- Por último se en esta foto hay varias idea de pequeños circuitos muy sencillos programados en arduino introduciendo el código blink (lo puedes encontrar eny ahí darle al apartado donde pone blink).
Aquí tenemos el ejemplo de como quedaría: (27/02/15) (De 9:25 a 10:20)
En esta última imagen se muestran algunos ejemplos sencillos que se pueden realizar:
No hay comentarios:
Publicar un comentario