To start, I want to say a student at a lab wheere I work really helped me better understand all of the components I needed to include to make this happen and I couldn't have gotten to this point (or it would have been a while longer) without picking his amazing brain! There are lots of different kinds of rotary encoders and you can make your own. A rotary encoder is a device that converts the angular position or motion of a shaft or axle to analog or digital output signals. I chose this type of input because I want the mechanism by which the color changes to be something along the lines of physically turning a knob... I realize there are many other ways I culd have done this but I ultimately decided to go in this direction. There are five pins to a rotary encoder: CLK for click (output A), DT (output B), SW for switch, + (vcc), and GND for ground. To begin, I wanted to try doing this with an Adruino and that meant CLK and DT needed to go to digital pins 2 and 3 and SW could go anywhere. I collected some supplies to get going which included a breadboard, jumper wires, and the rotary encoder itself. The first question though was does the rotary encoder have bounce. More on debouncing here. Switch bounce is literally bounce... most components I would use don't have good electro magnetic contact. Big cheap switches can have a waveform that can be somewhat eratic even with the span of a milisecond. Bounce in a mechanical switch can mess up an interrupt service routine in a microcontroller which we'd like to avoid. Some rotary encoders something in the them that eliminates most of the bouncing. If it doesn't have debouncing then we will need to add some small capicitors. The way we find this out is to use an oscillioscope.
So I had never used an oscillioscope before today so i looked it up... "An oscilloscope, previously called an oscillograph, and informally known as a scope or o-scope, CRO, or DSO, is a type of electronic test instrument that graphically displays varying signal voltages, usually as a calibrated two-dimensional plot of one or more signals as a function of time." - Wikipedia. Let's break that down... they are kinda like a really dope multimeter that just samples voltage like a million times per second... with a screen and you can also export data (csv or png file) you can also modify the resolution of your voltage sample. This is a digital one which is great because it doesn't take forever to warmp up. The one in our lab is a RIGOL rated at 100megahertz... it seems like once you get past that, these get pretty expensive. We added some colorful rings called marking bands to keep track of what we were hooking up. There are two channels and an external trigger (which is not an aquisition channel) you can set up.
Before I dive into color, another tip about how to use Arduino with Neopixels: you need to download the library. At the beginning, I only read the beginning of this, but this documentation by Adafruit is very helpful. Also, can I just say, it's really empowering to see the culture at Adafruit and the company they are... and that women run it! Limor Fried is so inspiring! This is another site that helped get the code started.
So I originally just thought to use RGB because that's all I knew to use. Turns out RGB isn't ideal for what I'm trying to do. The video above is what my neopixels look like when I use code rooted in RBG. I researched this and started learn more about other color models and color spaces here. I then decided to try out HSL or HSV. HSL (hue, saturation, lightness) and HSV (hue, saturation, value, also known as HSB or hue, saturation, brightness) are alternative representations of the RGB color model. Turned out the best information I could find was on this Wikipedia page.
See first iteration of code here.
See second iteration of code here.
This is final code and it worked!
I chose to use KiCad instead of Eagle because it's open source and some peopl I know like it more than Eagle so I figured I'd give it a go since I'm not attached to Eagle yet. First, I will briefly describe the components I think I will need for this board and why.
I had the AtTiny1614 on hand and decided to go with it. I then had to find a few things out from the datasheet.
I then needed to figure out how to download the library of components and found ot how to do that here.
So I did watch a few tutorials about KiCad since this was my first time using it and honestly most of them wern't helpful because they were from a past version and apparently it s changed quite a bit. So of course, as you can see above, I started running into alot of errors.
At this point, I performed a ton of continuity tests and found I had a short circuit near the capacitor and the at tiny. I spent about an hour de soldering and re soldering everything until the multimeter stopped making that irritating buzzing noise which meant, no more shorts!! Maybe... lol. I went to sleep. Tomorrow I will try to program it and then we will really know what went wrong.
This turtorial is extremely helpful. It goes through step by step how to program the AtTiny processors. Also my man Spence has some important information here on the chnages made in the tinyNeopixel library.
And then I got this error 100 times. AHHHH!!!!!!! I tried adding a capacitor.. then it just happened but later. I took out the resistors, added the resistors back, changed the code... checked the breadboard, used THREE different arduinos... D: I think I'm going to make a new board now because I did have a hard time soldering the ATtiny1614 and maybe I busted it?
So this was all the error of my soldering... After a million continuity tests, I fixed all the issues for the time being so now onto new errors hopefully within the software!
We added a 10kiloOhms resistor between switch and VCC becuase there was no pull up resistor so the line was floating in the electrical breeze. Also, we added a 10 mf capacitor between GND and switch so even if bounce was called by tapping or moving the lid, it would need to be longer than a few microseconds long.
At this point, everything kinda of fell into place quickly and you can see the final product in my video!