I have made two more led shows. One is just a normal wipe and the other is a wipe that changes colour. The normal wipe was incredibly easy and I didn't really have any problems making it, I just forgot to initialize the leds after set their colour so the colour wouldn't show up. The colour change wipe I had a little confusion with. I ended up finding a function provided with the adafruit neopixel library called "Wheel" that would change the values of the leds.
0 Comments
I have made two more led shows. They are called "Dashes" and "DashErase". "Dashes" one by one, kinda like a chase, makes a bunch of dashes on the led strip and once they are done being made they just stay there. "DashErase" does the same thing as "Dashes" however once the dashes are formed it then proceeds to erase the dashes in the same fashion that it formed them. There was quite a bit that had to be done to figure out how to make these work. At first I was trying to figure out completely by myself how to make the dashes work but after like and hour and half, almost two hours I decided to see if I could find something that might help. I ended up looking at the "theatreChase" function in the ButtonCyclerLedStrip program that I originally used to help me figure out how to make a button work. Although the theatre chase led show is a fair bit different from what I wanted, it ended up helping me figure out what I needed to do to make my "Dashes" function work. Then after I had figured out how to make "Dashes" work, figuring out "DashErase" was super easy. All I had to do was add another for loop that drew the dashes but instead of drawing, it erased the pixels. There have been a few issues that I have come across while making led shows. First I made "Chase", which I didn't really have any issues with, because I used example code to make it. Although I did have to learn what unsigned variables are because the example code used them. Signed and unsigned variables of the same type both represent the same number of values however unsigned variables can only be positive, so for example, an unsigned byte can represent values from 0 to 255, while signed byte can represent -128 to 127. I also had to go +and learn how to make a for loop in arduino which I found out you need to pass three statements, the initialization statement, the end condition statement, and the increment statement. Next I made the "Bounce" function. I knew that while the chase was first going across the strip it would be the same as the normal chase. However, once it got to the end, I had to figure out how to make it stop and come back the other way. It took me a little bit to come up with the math but eventually I figured it out. All I had to do was run a normal chase but in its own for loop after the first one and make it run exactly backwards compared to the first chase, so I just basically flipped all the values I was using. Next I made the "DoubleBounce" function. It was relatively simple, all i had to do was make two chases that were going opposite of each other that, and I had to make sure they moved at the same time, which I could by putting them in the same for loop. However when making them bounce back I had some troubles. All I had to do was take the first and swap the colors between the two different lines that drew pixels, however I spent quite a bit of time trying to make some complicated math that would work, but eventually I figured it out. The next led show that I made was the "DoubleHalfBounce". This one was quite easy to make as I already knew how to make the "DoubleBounce", the only thing i needed to figure out was how to make the chases stop in the middle and then go back to the edges. I ended up getting over this by dividing my end condition by 2 so that the chases would stop in the very middle. I also had an issue where whenever i would push a button it would wait until the specific led show it was on finished and then it would switch. I ended up fixing this by throwing an if statement in each led show function that would forcibly end the function if the current case number didn't match up with what the current led show should be. I also had a problem where the leds from the previous led show would stay on until they were overwritten with the new led show. I fixed this by making a little function that would go through every led in the strip and set its colour values to 0 and I stuck this function in with the if statements that would end the led show functions. So of course actually making the led shows is the most important part of this project. To start I first found some example code that made a simple chase and by analyzing this code I figured out how to make a chase and expanded upon that knowledge and simple math skills to make other led shows. At this point I have made 4 different types of led shows, a normal chase, a chase that bounces back and forth, two chases that go opposite ways and bounce back and forth, two chases that go opposite ways and bounce off each other in the middle every second time they go to the center. I plan to make a few more led shows So I forgot to mention this earlier but a big part of doing this project is relying on the Adafruit Neopixel Library. This is a library that provides a bunch of prebuilt code and such that allows you to use neopixels/addressable leds with your arduino without much difficulty.
So for my project to work I do need to physically setup some stuff. The first thing I did was connect a power and ground from my arduino to my bread board. I connected just a normal ground but for the power I connected the Vin pin instead of the normal 5V. I did this because the Vin pin gives outputs 5V if the arduino is already powered, however if the arduino isn't powered by say the USB or barrel plug you can hookup a 5V power source to the breadboard and the Vin will accept that as a power source, and then you can also power the led's with that same power source. So the Vin pin can be used as both a power in and power out. Next I have pins 2 and 3 which are being used as input pins for my buttons. I'm using pins 2 and 3 because they are the only pins on the arduino uno that are setup to be used with the arudino's built in interrupt routine. Finally on my arduino i'm using pin 0 as the output that sends signals to my led strips, data line so that i can make it do stuff. On my breadboard I have a few things going on. First of all i have my ground and Vin pins connected to the bottom of power rails on the breadboard. Then i have the power cords for the led strip plugged into the power rails as well. Next i have a cable bringing power to a button then on the otherside of the button I have a resistor connecting to the ground and I have a cable that goes to the corresponding input pin in my arduino. I have another button setup as well that ends going to the other input pin. Finally I have a cable coming from the output pin on my arduino then going to a resistor, then going to the data line cable for the led strip. Finally on my led strip I have three cables. The two outside ones being my positive and ground cables, red and blue respectively. There is alos the middle cable which the data line for the led strip.
So I have figured out how to switch between led shows using a function called switch. All i have to do is run the function in loop and I input the value of what led show i am on (as an integer). So the switch function ends up running the function that corresponds to the value it is given and then runs everything after that, but you can make it only run the specific function by breaking the switch function. Now that I have figured out how to do interrupts, the next thing I need to figure out is how to switch between led shows when an interrupt is triggered.
So I just figured out how to fix my interrupt issues. I found out that by using a function called "millis()", which counts real time in milliseconds, i can make it so that once the button is pushed it won't run the ISR again until a certain amount of time has passed.
I've been having some issues with using the button's inside ISR's. My first issue is that when I use normal button code that I have, the interrupt will only run once than stop working. The next issue is when I set it up to only change the Led show type it ends running the ISR 1-3 times, almost randomly it seems, and all my attempts at debouncing the button have not succeeded.
|
What's Going on Here?This is Ethan's blog about the progress done on their Capstone Project (final project) for their Computer Science 30 course.
Resources UsedArduino Reference Page
Interrupt Reference Interrupt Millis Function Arduino Forum Page Adafruit Button Help Sub Reddit Button Help Example Code UsedThe Led ShowsMy ProjectClick Here to go and take a look at the code for my project and maybe even download and use it if you want.
|