When I first started with this tutorial, I was excited because it seemed like it was just a refresher on the previous guide and tutorial on photoresistor usage and implementation. The circuit was easy to run through, but I got stuck on the whole “map” function deal.
A quick google search yielded this page from Arduino. I initially thought it gave the arduino another option in light output, allowing for more “in-between” values (instead of digitalWrite HIGH & digitalWrite LOW).
However, THIS guide summarized the map function as an analog/digital conversion- “The map function is intended to change one range of values into another range of values and a common use is to read an analogue input (10 bits long, so values range from 0 to 1023) and change the output to a byte so the output would be from 0 to 255.”
So, from my understanding, the analog input (the photoresistor) would send the arduino values, but the code would convert the range of values into something with a greater span, so an easier transition could be had from a brighter to a dimmer output. While it wasn’t exactly what I was thinking it would do, this was cool because it gave me the option to make the light for my final sloooooowly turn on as the sun set, as opposed to a harsh on/off when the read values from the photoresistor fell or rose above a specified value.
However, with that in mind, I knew this would be rough to implement because coding isn’t exactly my strong suit. I wasn’t able to get it to work as planned, but this was the code I thought would work best.
While I wasn’t able to get any of the other assignment features complete (integrate a potentiometer or a second component in general), I’m happy I have a better understanding of the analog side of the arduino!
No comments:
Post a Comment