my question is, i will control the dimmer with an analogue PWM value right? so how do i scale the values the PING sensor gives me down to a 0-255 range, or a 0-5v range. must i use a function, or can this be automated?
i will control the dimmer with an analogue PWM value right?
Well no not directly. The PWM output needs to be boosted to 12V using a transistor. Then it needs to be smoothed using a series resistor, and a capacitor and then it can be applied to your controller.
i scale the values the PING sensor gives me down to a 0-255 range
Just scale it using a y = mX +C type of formula. Think about it.
Quote:
i will control the dimmer with an analogue PWM value right?
Well no not directly. The PWM output needs to be boosted to 12V using a transistor. Then it needs to be smoothed using a series resistor, and a capacitor and then it can be applied to your controller.
The dimmer manual says "Use an adjustment voltage of 0 to 5 (or to 12V max). And it has two pots for adjusting min/max.
Just scale it using a y = mX +C type of formula. Think about it.
I wish that scaling would be a default when passing a value to a limited range port. Like in Isadora.
Can you please explain your formula, if it's simple.
i am trying to get the range 200-13000 squeezed into 0-255.
The ping just sends and receives a pulse it does no calculations so you will need to do that part anyway and you can just add that into the scaling mix. Once the code is written it will become automatic to the end user.
there is a function for scaling values, look up map function.
Yes in deed I keep forgetting the wimps functionality.
let S = sensor reading of a sensor range 200 to 13000
so S-200 will give you a range of 0 to 12800
if you have a maximum value of 12800 you want to map this to a value of 255 so divide it by 12800/255 = 501.96 lets call it 502.
A maximum value of 12800 / 502 = 255
Therefore to convert simply:-
converted = (S - 200)/ 502
Mike probably writes his code in hex because its less wimpy than C or C++
How did you know?
Because I guessed you started to first write code at around the same time I did, back in the good old days when wimps wrote in assembler and real programmers wrote in hex (or octal) ;D