So, this is my first time messing with a potentiometer on the arduino. I have a simple script that checks each of the analog channels for values above 512, and the first (a0) just relays the mapped value to an led on pin 13 (softpwm). The confusing part is, after the pot gets a quarter or so the way through spinning, the led is at max brightness, and if I spin it further, the rest of the analog pins act as if switches have been turned on.
I can understand the pot going to full in only a quarter turn. It's just the wrong resistance level (10k pot), but what I don't get is why the rest of the analog pins are acting as if the switches are turned on. The only thing I can think of is they have a noise variance because I didn't feel like hooking up any resistors, but they shouldn't they always act like they are on? (Also, what size pot do I need to make a full turn = max on an arduino. I'm still fairly new to electronics, but shouldn't I need a smaller resistance pot? Like a 5k?)
I know it should be simple, and it's probably something that's my fault, but Can someone help me out a little?
I forgot to mention I already used the map function to resize the input. (Why I didn't just divide by 4 instead of using the map function, I don't know though.)
As far as the code with respect to the quarter turn, I had this:
SoftPWMSet(13, floatMap(analogRead(0),0,1024,0,255));
//(Float map is the same as Map, but with floats instead. Better precision in many cases, IMO, especially when scaling up instead of down.)
and changing it to be the simpler math,
SoftPWMSet(13, analogRead(0)/4);
As for hooking it up, I have it like the "New" one in this image:
where pin three is going to A0, and +5v input is from the 5v rail of an Arduino Duemilonove (spelling wrong I'm sure... O-o I always get it wrong XD).
Have you tried just printing out the output from the analogRead() method? It would be helpful to know if the problem is in reading the analog pin or in converting it for softPWM.
I found out what my problem was. I was doing the 255 max value for softPWM, and it's percentage based, 100 max. That's why I was off. Seems to be working well now though.