Week 6,

×

Ideation Phase: For this week, we just had to make our milled board from Week 4 do something. Since I'd only included a button and LED as additions to my board, I was a bit limited in what I could do. I didn't just want to turn my LED on and off, though, so I decided to implemenet a variable PWM for my LED which depended on how long the user pressed the button for.

×

Execution Phase : Despite the actual writing of the code not taking too long, as soon as I started trying to upload the code to my microcontroller, chaos ensued. At first, my code refused to compile because it took up more memory space than available on the board. I found that a bit hard to believe considering how simple my code was. All it did was turn an LED on and off. Regardless, I never ended up finding a solution to this problem as it simply stopped existing when I returned to my code a few hours later. Instead, the new problem was that while my code compiled, it wasn't visible on my computer ports. When I returned to my finnicky board the following day, I realized that I had accidentally flashed my board to not use USB communication which solved my compiling issue as it took less space but made it impossible for my computer to see my board. Once I'd resolved that by reburning my board's bootloader with my programer from Week 2 and enabling USB communication, I found out that my LED was on backwards (the side with the faint green line should be connected to ground) and I'd accidentally used a way too big resistor (the code 1004 means 100 * 10^4 which is a Megaohm when we really wanted a resistor with the code 1003 -- a kilohm). After fixing those board issues, I was ready to flash my code. Weirdly enough, my code only worked when I uploaded it directly through USB rather than using a programmer, despite the fact that the behavior should be the same. I was not in the mood to debug things that weren't my own code so I decided to just use my USB to upload and ignore that strange issue.

Alas, things were still not working. First of all, space is limited on the SAMD11C (for context, my final code took about 97% of available memory). While I had scoffed at the possibility of running out of space by only turning on a LED, I spoke to Anthony and apparently that was a very real possibility. Realizing, I didn't have space to spare, I had to be intentional with my functionality. I definitely needed to include a button debouncer just so my button state wouldn't be switching willy-nilly due to noisy signals but that took away available memory. That meant the division I intended to for my PWM implementation would no longer be possible. I also just was no longer in love with my initial idea of a variable PWM. Because of this, I decided to pivot. My new program only turned the LED on if you had held the button longer than a random number less than 500ms. Here's the code and a screenshot for reference:
screenshot of my code :)

×

Final Product: It worked!...I think? Because it's not always supposed to turn on, as the random number may be greater than the time I held it for, it's hard to know what's a bug and what's a feauture. Regardless, I took this as a win and called it a day. Here's the video of it working:

Update: I did some more testing and it does definitely work as intended. We absolutely love to see it. You can see the real-time logic in the adjacent video above (the data-readings come in groups of three: the first two are the press duration and random number, respectively, while the single digit number is if the button is on or not).

- Alex