Hey, I'm making an arduino car for my programming exam. The car has two LED's on the front, who I only want to give half power. I'm going to use an analogWrite, and in the loop, I'm gonna set the analogWrite value of the LED's to 125 (since a LED's range is from 0-250).
My problem is; I want to give the LED 125 as a Value (which is half of its capacity), BUT, the analogWrite "spectrum" goes from 0 - 1023. So if i Write 125 as the analogWrite value, the result is really low...
If anyone understand my problem, please help me with the converting...
You've got analogWrite which takes 0 to 255 confused with analogRead that gives 0 to 1023. If you want half power write analogWrite(127). Note that half power and half brightness might well be 2 separate things. To get the latter you may need to play around with the values a bit.
So, I want the LED to have only half *Brightness (my bad) but if I write 127 in analogWrite, nothing happens becouse even though 127 is about the half of 255, 127 is just a little bigger than a tenth of 1023, so that doesnt work :S
What the he'll does 1023 have to do with it? Nothing. That's the max for READING analog values. 255 is full on for WRITING analog. If you want 50% duty cycle PWM then that is 127.
short pin to breadboard -> 220 recistor from the same line as short pin, to minus (on the plus/minus lines on the breadboard). -> minus from breadboard to ground on arduino.
long pin from LED to digitalPin 30 on the Arduino.
Fml... I have to wire it to an analogpin on the Arduino right?...
You have to write to an analog OUTPUT. Not one of the analog inputs. It will be,one of the digital pins with the little ~ symbol next to it. If you try to call analogWrite on a pin that doesn't support PWM then anything 127 or less writes LOW and anything 128 or higher writes HIGH.
Hahah, im just really tired... Changed the pins and everything worked perfectly, thanks alot didn't think of that, only had to PWM pins left to use so didn't see it haha Oh, i didn't know 44-46 was PWM aswell, thats nice. Thanks alot for the help