Hi Guys,
i just want to know, can arduino invert pwm values?
eg i have this vector
int pwm_values[3]={25,35,80};
and i want to invert the numbers in the vectors such that each value is (256-25),(256-35),(256-35),(256-80) ..... ?
Hi Guys,
i just want to know, can arduino invert pwm values?
eg i have this vector
int pwm_values[3]={25,35,80};
and i want to invert the numbers in the vectors such that each value is (256-25),(256-35),(256-35),(256-80) ..... ?
Are you asking for permission? Or how to?
Yes, you can have the Arduino use the "inverse" of the value in the vector, just like you show. There is no magic way to do it, though.
Hi,
yep, i wanted to know how to do it..
so does that mean i have to create some type of condition so to subract 256 from each of the vector values ?
so does that mean i have to create some type of condition so to subract 256 from each of the vector values ?
No. You want to subtract the vector value from 255, just as you showed.
int pwm_values[3]={25,35,80};
analogWrite(redPin, 255-pwm_values[0]);
analogWrite(grnPin, 255-pwm_values[1]);
analogWrite(bluPin, 255-pwm_values[2]);
Thanks, thats simply enough. whilst on the topic of subtractions, arduino returns a zero value if i were to have the equation
int a;
intb;
b=3.5
a= b *2
how would i get arduino to mutliply decimal numbers.Im assuming i use the function float ?
Your help is greatly appreciated
If b is an int, trying to assign it a value of 3.5 results in it being assigned a value of 3. Multiplying 3 by 2 results in a value of 6, which should be correctly stored in a.
If you are getting different results, post some real code.
yes you are correct, my code is very long, and i was multiply by 0.55, which returned a zero for my case. In my last question i was just providing an example.
In any case, how would you go about directing arduino to multiply by 0.55, or 3.5 ?
i am very new to programming, so help is greatly appreciated.
In any case, how would you go about directing arduino to multiply by 0.55, or 3.5 ?
A question like this can not be answered out of context. Are you multiplying an int by 0.55, or a float? Do you expect the result to be truncated, or not? If not, the result can not be stored in an int.