Hide minor edits - Show changes to markup
También podemos ejecutar este ejemplo "Coche Fantástico Knight Rider" en memoria de una serie de televisión de los 80 donde David Hasselhoff tenía una máquina de IA llamada KITT que conducía su Pontiac. El coche había sido provisto con un montón de LEDs en todos los tamaños posibles para realizar efectos llamativos. En particular, tenía un display que escaneaba de un lado a otro en una línea, como se muestra en esta emocionante lucha entre KITT y KARR. Este ejemplo replica el display de KITT.
También podemos ejecutar este ejemplo "Coche Fantástico (Knight Rider)" en memoria de una serie de televisión de los 80 donde David Hasselhoff tenía una máquina de IA llamada KITT que conducía su Pontiac. El coche había sido provisto con un montón de LEDs en todos los tamaños posibles para realizar efectos llamativos. En particular, tenía un display que escaneaba de un lado a otro en una línea, como se muestra en esta emocionante lucha entre KITT y KARR. Este ejemplo replica el display de KITT.
This example makes use of 6 LEDs connected to the pins 2 - 7 on the board using 220 Ohm resistors. The sketch makes the LEDs blink in a sequence, one by one using only digitalWrite(pinNumber,HIGH/LOW) and delay(time).
click the image to enlarge
El ejemplo se hace uso de 6 LEDs conectados a los pines 2 a 7 de la placa utilizando resistencias 220 Ohm. El programa (sketch) hace que los LED parpadeen en secuencia, uno por uno con tan sólo digitalWrite(pinNumber, HIGH/LOW) y delay(time).
haz click en la imagen para ampliar
image developed using Fritzing. For more circuit examples, see the Fritzing project page
Schematic:
click the image to enlarge
image developed using Fritzing. Para mas circuitos de ejemplo, visita la página del proyecto Fritzing
Esquema:
haz click en la imagen para ampliar
Examples > Control Structures
Examples > Estructuras de Control
Often you want to iterate over a series of pins and do something to each one. For example, this example lights up a series of LEDs attached to pins 2 through 7 of the Arduino.
We also call this example "Knight Rider" in memory of a TV-series from the 80's where David Hasselhoff had an AI machine named KITT driving his Pontiac. The car had been augmented with plenty of LEDs in all possible sizes performing flashy effects. In particular, it had a display that scanned back and forth across a line, as shown in this exciting fight between KITT and KARR. This example duplicates the KITT display.
A menudo buscas iterar sobre una serie de LEDs y hacer algo con cada uno de ellos. Por ejemplo, este programa enciende una serie de LEDs conectado a los pines 2 a 7 de Arduino.
También podemos ejecutar este ejemplo "Coche Fantástico Knight Rider" en memoria de una serie de televisión de los 80 donde David Hasselhoff tenía una máquina de IA llamada KITT que conducía su Pontiac. El coche había sido provisto con un montón de LEDs en todos los tamaños posibles para realizar efectos llamativos. En particular, tenía un display que escaneaba de un lado a otro en una línea, como se muestra en esta emocionante lucha entre KITT y KARR. Este ejemplo replica el display de KITT.
/* For Loop Iteration Demonstrates the use of a for() loop. Lights multiple LEDs in sequence, then in reverse. The circuit: * LEDs from pins 2 through 7 to ground created 2006 by David A. Mellis modified 5 Jul 2009 by Tom Igoe http://www.arduino.cc/en/Tutorial/ForLoop */
(:includeurl http://arduino.googlecode.com/svn/trunk/build/shared/examples/Control/ForLoopIteration/ForLoopIteration.pde border=0:)
int timer = 100; // The higher the number, the slower the timing.
void setup() { // use a for loop to initialize each pin as an output: for (int thisPin = 2; thisPin < 8; thisPin++) { pinMode(thisPin, OUTPUT); } }
void loop() { // loop from the lowest pin to the highest: for (int thisPin = 2; thisPin < 8; thisPin++) { // turn the pin on: digitalWrite(thisPin, HIGH); delay(timer); // turn the pin off: digitalWrite(thisPin, LOW); }
// loop from the highest pin to the lowest: for (int thisPin = 7; thisPin >= 2; thisPin--) { // turn the pin on: digitalWrite(thisPin, HIGH); delay(timer); // turn the pin off: digitalWrite(thisPin, LOW); } }
for (int thisPin = 0; thisPin < 8; thisPin++) {
for (int thisPin = 2; thisPin < 8; thisPin++) {
image developed using Fritzing. For more circuit examples, see the Fritzing project page
for (int thisPin = 0; i < 8; thisPin++) {
for (int thisPin = 0; thisPin < 8; thisPin++) {
for (thisPin = 7; thisPin >= 2; thisPin--) {
for (int thisPin = 7; thisPin >= 2; thisPin--) {
(:divend:)
(:divend:)
Examples > Control Structures
Often you want to iterate over a series of pins and do something to each one. For example, this example lights up a series of LEDs attached to pins 2 through 7 of the Arduino.
We also call this example "Knight Rider" in memory of a TV-series from the 80's where David Hasselhoff had an AI machine named KITT driving his Pontiac. The car had been augmented with plenty of LEDs in all possible sizes performing flashy effects. In particular, it had a display that scanned back and forth across a line, as shown in this exciting fight between KITT and KARR. This example duplicates the KITT display.
This example makes use of 6 LEDs connected to the pins 2 - 7 on the board using 220 Ohm resistors. The sketch makes the LEDs blink in a sequence, one by one using only digitalWrite(pinNumber,HIGH/LOW) and delay(time).
click the image to enlarge
Schematic:
click the image to enlarge
(:div class=code :)
/* For Loop Iteration Demonstrates the use of a for() loop. Lights multiple LEDs in sequence, then in reverse. The circuit: * LEDs from pins 2 through 7 to ground created 2006 by David A. Mellis modified 5 Jul 2009 by Tom Igoe http://www.arduino.cc/en/Tutorial/ForLoop */
int timer = 100; // The higher the number, the slower the timing.
void setup() { // use a for loop to initialize each pin as an output: for (int thisPin = 2; thisPin < 8; thisPin++) { pinMode(thisPin, OUTPUT); } }
void loop() { // loop from the lowest pin to the highest: for (int thisPin = 0; i < 8; thisPin++) { // turn the pin on: digitalWrite(thisPin, HIGH); delay(timer); // turn the pin off: digitalWrite(thisPin, LOW); }
// loop from the highest pin to the lowest: for (thisPin = 7; thisPin >= 2; thisPin--) { // turn the pin on: digitalWrite(thisPin, HIGH); delay(timer); // turn the pin off: digitalWrite(thisPin, LOW); } }
(:divend:)