7 Color LED
#1
Posted 21 December 2010 - 03:33 AM
#2
Posted 21 December 2010 - 08:34 PM
#3
Posted 21 December 2010 - 08:46 PM
#4
Posted 22 December 2010 - 12:45 AM
#5
Posted 22 December 2010 - 02:27 AM
public class Program { static bool buttonState = false; static PWM led; static int pwmCycle = 0; static int maxPwm = 1; static int pwmDirection = 1; public static void Main() { led = new PWM(Pins.GPIO_PIN_D5); InterruptPort button = new InterruptPort(Pins.ONBOARD_SW1, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth); button.OnInterrupt += new NativeEventHandler(button_OnInterrupt); Thread.Sleep(Timeout.Infinite); } static void button_OnInterrupt(uint data1, uint data2, DateTime time) { if (!buttonState) { pwmCycle += pwmDirection; led.SetDutyCycle((uint)pwmCycle); if ((pwmCycle == maxPwm) || (pwmCycle == 0)) pwmDirection = -pwmDirection; } buttonState = !buttonState; } }
Update: Updated to reflect Mr. Walker's excellent recommendation.
#6
Posted 22 December 2010 - 03:01 AM
#7
Posted 22 December 2010 - 03:03 AM
#8
Posted 22 December 2010 - 03:05 AM
I'm curious: This LED has a FW current of 35mA but the pins can only output 8 or 16 max it looks like, so how would this need to be wired? I bought one of the LEDs but I don't have a breadboard yet, it's coming tomorrow - so I can mess with it then.
Sorry if it's a bad question, I'm still learning the basics.
WannaFly, you'll generally want to place a (current-limiting) resistor in series with the LED(s).
Chris
#9
Posted 22 December 2010 - 03:28 AM
#10
Posted 22 December 2010 - 03:39 AM
Is that the correct thinking? If so where does the 8mA from the pin come in?
If attached to a 16mA pin, you'll want to limit the current to <=16mA. For an 8mA pin, limit the current to <=8mA.
Technically, hooking LEDs directly to microcontroller pins without resistors isn't the worst thing you could do...but using current-limiting resistors is best practice.
Chris
#11
Posted 22 December 2010 - 05:29 AM
public class Program { static bool buttonState = false; static OutputPort led; public static void Main() { led = new OutputPort(Pins.GPIO_PIN_A5, false); InterruptPort button = new InterruptPort(Pins.ONBOARD_SW1, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth); button.OnInterrupt += new NativeEventHandler(button_OnInterrupt); Thread.Sleep(Timeout.Infinite); } static void button_OnInterrupt(uint data1, uint data2, DateTime time) { buttonState = !buttonState; led.Write(buttonState); } }
Again, this is with the Neg leg being grounded, the middle (pos) leg with a line to 3.3v and the switch leg (the 45 degree) hooked up to Analog pin 5. This allows you to cycle through the 7-color LED set.
Thank you all for your help in educating me. I have a good ways to go!
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users