I would like to do,
analogWrite(100,3);
analogWrite(200,6);
at the same time. But the problem is that only the led on pin 3 lights up. I want both to light up at the same time. I've heard about direct port manipulation, but I can only find an alternate for digitalWrite()
but I couldn't find one for analogWrite()
. Can someone please help me with just a simple example on just how to do the above operation?
I'm using arduino uno.
1 Answer 1
You have your parameters the wrong way round:
analogWrite(2, 100);
analogWrite(6, 200);
However: pin 2 on the Uno cannot do PWM, so you will have to pick a different pin. Look for the pins marked with ~
- they are the PWM pins. On the Uno that is pins 3, 5, 6, 9, 10 and 11.
-
yeah I'm sorry it's pin 3. Now how to i turn both on at the same time?Rishi Swethan– Rishi Swethan2017年04月18日 11:29:28 +00:00Commented Apr 18, 2017 at 11:29
-
Just like that. When you run
analogWrite()
it starts PWM on that pin and it keeps going until you tell it otherwise. If you aren't getting anything out then you have probably broken that pin through misuse or doing something else in your code that's stopping PWM.Majenko– Majenko2017年04月18日 11:30:18 +00:00Commented Apr 18, 2017 at 11:30 -
No. if i use pin 6 first, then pin 3. The pin 6 lights up and not pin 3Rishi Swethan– Rishi Swethan2017年04月18日 11:33:21 +00:00Commented Apr 18, 2017 at 11:33
-
And if you do it the other way around? And NOT PIN 2.Majenko– Majenko2017年04月18日 11:33:54 +00:00Commented Apr 18, 2017 at 11:33
-
analogWrite(6, 100); analogWrite(3, 200); This turns on pin 6Rishi Swethan– Rishi Swethan2017年04月18日 11:34:24 +00:00Commented Apr 18, 2017 at 11:34