Go Down

Topic: Project 14-tweak the logo - possible to use more than one potentiometer? (Read 1 time) previous topic - next topic

randy41

Hi there,

I just finished project 14, tweaking the Arduino logo (with a little help from the forum and a couple of tweaks to the code).   I notice that in the HSB color mode, there are 3 arguments - one for hue, one for saturation, and one for brightness.  Is it possible to write code that would allow the user to control the value of each of these arguments with separate potentiometers?  If so, how would one go about doing that?

Thanks!

randy41

In case anyone is curious - I figured out a way to do this.   It's probably not the best way, but I tried it, and it worked.

I created variables for hue, saturation, and brightness, the values of which were tied to pots connected to A0, A1, and A2.  I also created variables for past values for each of these, so that the IDE could check to see whether these values had changed.
As in the original logo project, I divided the analog values by 4 so that their max value would be 255, which is the limit of the Serial.write command (according to the projects book).  Then I divided the resultant values again by 3, which gave me a max value of 85. 

For the hue pot, I kept this value.  For saturation, I added 85.  For brightness, 170.  I had the IDE check the current pot values against the past values, and if they were different, then I had the IDE Serial.write the new values and update the past ones.

From here, because all the hue values fell between 0 and 85, all the saturation values fell between 86 and 170, and all the brightness between 171 and 255, I was able to program Processing to differentiate between a change in hue vs brightness vs saturation based on where their values fell within these ranges.  I programmed Processing to do the reverse math (subtracting 0 for hue, 85 for saturation, or 170 for brightness, then multiplying the results by 3) to get values ranging from 0-255, and then set the background argument to these values (hue, saturation, brightness).

Hope that makes sense.  It was a fun problem to solve, if nothing else.  :)

Go Up