Running a One Through a Field of Zeros
Intro: Running a One Through a Field of Zeros
Back in the 70's I was working for Northern Telecom (Nortel Networks). I attended a digital electronics course and part of the course dealt with LED's and flip flops.
One of the tasks we had to perform was called Running a one through a field of zeros. In this example we have six LEDs that are turned off and each LED had to be turned on then off through the entire sequence of LEDs.
It was a lot of wiring and I probably could not do it today and why would I? Using the Arduino board is so much easier!
This example is for beginners or the curious.
If you want to try this example you will need the following parts:
6 LEDs.
6 330 ohm resistors.
1 Arduino Clone.
7 jumper cables.
1 Breadboard.
You can power this example through the USB port.
======================================================================
Here is the code: You can copy and paste into your IDE.
/* Running a one through a field of zeros This example code is in the public domain. */
// give the LEDs a name and assign them a number:
int led1 = 2;
int led2 = 3;
int led3 = 4;
int led4 = 5;
int led5 = 6;
int led6 = 7;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pins as output.
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(led6, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop()
{ digitalWrite(led1, HIGH); // turn the LED on (HIGH is the voltage level)
delay(50); // wait
digitalWrite(led1, LOW); // turn the LED off by making the voltage LOW
delay(50); // wait
digitalWrite(led2, HIGH); // turn the LED on (HIGH is the voltage level)
delay(50); // wait
digitalWrite(led2, LOW); // turn the LED off by making the voltage LOW
delay(50); // wait
digitalWrite(led3, HIGH); // turn the LED on (HIGH is the voltage level)
delay(50); // wait
digitalWrite(led3, LOW); // turn the LED off by making the voltage LOW
delay(50); // wait
digitalWrite(led4, HIGH); // turn the LED on (HIGH is the voltage level)
delay(50); // wait
digitalWrite(led4, LOW); // turn the LED off by making the voltage LOW
delay(50); // wait
digitalWrite(led5, HIGH); // turn the LED on (HIGH is the voltage level)
delay(50); // wait
digitalWrite(led5, LOW); // turn the LED off by making the voltage LOW
delay(50); // wait
digitalWrite(led6, HIGH); // turn the LED on (HIGH is the voltage level)
delay(50); // wait
digitalWrite(led6, LOW); // turn the LED off by making the voltage LOW
delay(50); // wait
}
Making things do stuff by writing code is SO much easier!
If you want another challenge try running a zero through a field of ones by changing the code!
6 Comments
rutcorn 8 years ago
AndrewW180 8 years ago
Hey. Post the code for the array....It would give people an option they can try.
Thanks!
rutcorn 8 years ago
Here's the code for the array. It does compile, but I didn't do any further testing (too lazy to make a project in 123circuits :) ). All should work fine.
/***** START OF CODE *****/
/* Running a one through a field of zeros This example code is in the public domain. */
// Make an array holding the pins numbers to which the LEDs are connected
char led[6] = { 2, 3, 4, 5, 6, 7 };
// the setup routine runs once when you press reset:
void setup() {
// for loop is used to access every LED pin (indexes 0-5)
for (char i=0; i<6; i++) {
// initialize the digital pin (with index i) as output.
pinMode(led[i], OUTPUT);
}
}
// the loop routine runs over and over again forever:
void loop() {
// turn LED on, wait a bit then turn it OFF
// the for loop takes care of running all the LEDs in sequence
for (char i=0; i<6; i++) {
// turn the LED (with index i) on (HIGH is the voltage level)
digitalWrite(led[i], HIGH);
// wait 50 milliseconds
delay(50);
// turn the LED (with index i) off by making the voltage LOW
digitalWrite(led[i], LOW);
}
}
/***** END OF CODE *****/
AndrewW180 8 years ago
Yes, thank you!
This looks great!
So if anyone wants to try using an array just put rutcorn's code in place of mine and you can see how arrays work...
Great work Rutcorn!!
rutcorn 8 years ago
You're welcome! I'm happy to be of help.
AndrewW180 8 years ago
Thanks for the reply. Yes it would make things easier, however I made this as an example for beginners and wanted to keep it straight forward as possible.