
Current Arduino Tinkering & New Additions
First off I’d like to say, Happy New Years! Now that I’ve finished hanging out and staying up ridiculous hours hanging out with my friends, it’s time to crack down to business and address some updates that I’ve implemented to help me learn a bit more about Arduino and circuits while displaying my work on Github.

Fritzing, something I can finally understand over EagleCAD
I decided to document a progression of what I know from about Arduino from the beginning of my journey towards the end when I start doing projects that show some practical use. To do so, I was going to start using EagleCAD to draw schematics, but adding transistors, LEDs, and resistors were too complex in the program. With Fritzing, I can draw out a breadboard design and also show the PCB and schematic with ease. I have all of this uploaded onto my GitHub in a folder.
Beginner-Arduino-Work - A bunch of my early tinkering and work with the Arduino/Redboard.github.com
Check it out, I’ll be able to keep adding onto this folder the more I learn. What’s even better is that I’ll be able to link my code here from GitHub instead of linking a download link.
What I’ve done with Arduino so far…
Aside from all the new stuff I added documentation-wise, I’ve been incorporating what I’ve learned to light up multiple LEDs as well as create patterns. Take a look! You can also look at the code for this project on GitHub by pressing the link below.
Beginner-Arduino-Work - A bunch of my early tinkering and work with the Arduino/Redboard.github.com
Also, the code also shows a really good example of when to implement methods, which is a section piece of the whole code that does a specific process. You can call this method in your main portion of your code. In the Arduino language, it’s the void loop() method.
For further explanation, take an example method void onPinFive(). Let’s just say the code nested under this method was to set pin 5 on the Arduino to output 5V. You can then type onPinFive() inside void loop() and it will go to that method and use the code that’s inside there (which ultimately ends up with turning on pin 5).
Even though this example isn’t really practical since it takes one line of code to turn on a pin, you get the point. However, you’ll see better implemented methods as you go through the patterns below.
Pattern One: Lighting Up Each Light at a Time

As you can see, loop() is just a bunch of commented methods so that they aren’t read by the computer when sending this information to the board, but you can uncomment/comment these methods to your liking. For each of these pattnerns I’ll explain the logic behind each one. For this pattern, I used a for loop to turn turn on all these lights. The loop basically goes through each pin and turns them on.
for (int index = 0; index <= 7; index++) {
digitalWrite(ledPins[index], HIGH);
delay(delayTime);
}
Then, I used another loop to go through each pin to turn off each LED. Easy enough, right?
for(int index = 7; index >= 0; index — ) {
digitalWrite(ledPins[index], LOW);
delay(delayTime);
}
This logic can be found nested inside the oneAfterAnotherLoop() method.
Pattern 2: Individually Lighting up and Turning off an LED

The logic for this is pretty simple. If you think about it, for every time the light turns on, it needs to turn off again. That’s the same as saying: for each light, turn it on, then turn it off. Translating this to code, we get:
for(int index = 0; index <= 7; index++) {
digitalWrite(ledPins[index], HIGH);
delay(delayTime); //delay time is mentioned as 100 in the code
digitalWrite(ledPins[index], LOW);
}
This portion of the code can be found in the oneOneAtATime.
Pattern 3: Marquee (Chasing Lights) Pattern

This logic for this pattern is really similar to the logic from the previous pattern mentioned. This pattern also uses a for loop, but also utilizes the ability do multiple things per instance/interval in the loop.
For instance, for this pattern to work, the first LED and the LED that is exactly 4 LEDs away from it is turned on and then both turned off. After the loop, the second LED lights up and the light 4 away from it. This repeats over and over until the 3rd pin, is the last pin that should be turned on and then repeated (due to the small amount of LEDs placed on the breadboard).
for(int index = 0; index <= 3; index++) {
digitalWrite(ledPins[index], HIGH); // Turn a LED on digitalWrite(ledPins[index+4], HIGH); // Skip four, and turn that LED on delay(delayTime); // Pause to slow down the sequence digitalWrite(ledPins[index], LOW); // Turn the LED off digitalWrite(ledPins[index+4], LOW); // Skip four, and turn that LED off
}
This can be located inside the marquee() method.
Pattern 4: Ping-Pong Pattern :D

Pretty much, for loops are used whenever you want to repeat anything. For this instance, we are essential just running a loop to turn on and turn off each LED, and then make the loop go backwards. We can easily accomplish the task by splitting it into two jobs. Let’s make a for loop to light up the LEDs going forward.
for(int index = 0; index <= 7; index++) {
digitalWrite(ledPins[index], HIGH); // turn LED on delay
(delayTime); // pause to slow down
digitalWrite(ledPins[index], LOW); // turn LED off
}
Now, make a loop that does the same exact thing going backwards. All you have to do is change the parameters in the for loop. Set the index so that it cannot exceed past 0 (you can’t access a negative pin!) and make the index given (which starts at pin 7) and lowers every time you go through the loop.
for(int index = 7; index >= 0; index — ) {
digitalWrite(ledPins[index], HIGH); // turn LED on delay
(delayTime); // pause to slow down
digitalWrite(ledPins[index], LOW); // turn LED off
}
Pattern 5: Random Lighting

Finally, for this, we will utilize a new method in the Arduino libraries called random(). For this method just input a number that is one more than the amount you want. For instance, since we are using random(8) in our code, we are asking to generate a random number from 0 to 7 (which stands for pin 0 to 7 in the array of pins that we made). Then we ask it to turn on the LED at that designated pin.
There is no need for a for loop here because this method is already being looped. We are just asking it to select a random LED every time.
int index = random(8); // pick a random number between 0 and 7
int delayTime = 100; digitalWrite
(ledPins[index], HIGH); // turn LED on delay(
delayTime); // pause to slow down
digitalWrite(ledPins[index], LOW); // turn LED off
This can also be found in the randomLED() method.
That’s it!
That’s pretty much it for the LED patterns I’ve been messing around with. Next time I’ll be trying to implement push buttons and such. Hopefully, I’ll be able to soon implement LCDs, sensors, and many other things as well.
Once I learn enough about Arduino, I’ll finally be able to do a pretty nice project. Until next time!