Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

7 Color LED


  • Please log in to reply
10 replies to this topic

#1 ClosedEyesSeeing

ClosedEyesSeeing

    Member

  • Members
  • PipPip
  • 21 posts
  • LocationVirginia

Posted 21 December 2010 - 03:33 AM

Hi there! I just got my N+ and started playing around with it. I've gotten pretty comfortable with the on-board button and LED, and have decided to move over to the breadboard and try to light a 7-color LED from RadioShack. This is where my lack of engineering comes into play, I haven't a clue how to wire this up. With a standard LED I'm comfortable with the pos/neg legs to use, but with this LED there are 3 legs (from what I gather a ground, 3.3v, and a switch) and I find myself a little lost in how to wire it up. If anyone can help a poor noob learn a little here, I'd be greatly appreciative. Thanks, ClosedEyesSeeing

#2 WannaFly

WannaFly

    Member

  • Members
  • PipPip
  • 17 posts

Posted 21 December 2010 - 08:34 PM

I wish I could help but you're a step ahead of me. I'm planning on trying to hook up just a regular LED tonight after I get some resistors from radioshack. I'll pick up a 7 color LED and if I have time I'll mess with it also. So, If anyone else has suggestions, specifically on how to wire one up, I'd like to hear it also :) I'm trying to learn the basics of AC/DC circuits again, I took classes in college and they were great but it was 10 years ago - I don't remember much. I know it will definitely help.

#3 AlfredBr

AlfredBr

    Advanced Member

  • Members
  • PipPipPip
  • 138 posts
  • LocationConnecticut, USA

Posted 21 December 2010 - 08:46 PM

I've never seen one of these in real life, but there are a few posts from people who have used these successfully on the RadioShack link: http://www.radioshac...oductId=3060680 I'll try to pick one up on my way home, but from what I can gather, this is an LED with a built-in logic chip. The LED has several modes that are selected by pulsing the control pin. According to the guys on the link above: "Flat side is negative, middle leg positive and the pin with the dogleg is control lead."

#4 ClosedEyesSeeing

ClosedEyesSeeing

    Member

  • Members
  • PipPip
  • 21 posts
  • LocationVirginia

Posted 22 December 2010 - 12:45 AM

I've made a little head way in the bit I've been home. Just to test I have 3.3v going to the middle leg and bridged over to the 'switch' leg and the ground being grounded - naturally. When this fires up it seems to cycle through the various states (solid colors and blinking colors) then stops. I suppose the next step is to wire the switch leg to a digital line and maybe step via the button. I'll let you know!

#5 ClosedEyesSeeing

ClosedEyesSeeing

    Member

  • Members
  • PipPip
  • 21 posts
  • LocationVirginia

Posted 22 December 2010 - 02:27 AM

It isn't instant with the states but this seems to work pretty well. However, let me preface this with I have no idea what I'm doing. :)

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 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 22 December 2010 - 03:01 AM

ClosedEyesSeeing, Rather than using: while (true) { } I'd recommend: Thread.Sleep(Timeout.Infinite); The first will occupy a bunch of CPU cycles doing nothing (which is typical in microcontroller firmware), but the second takes advantage of a feature of .NET Micro Framework...the ability to sleep. Using the latter is best practice and it will speed up your code (and potentially save energy). Chris

#7 WannaFly

WannaFly

    Member

  • Members
  • PipPip
  • 17 posts

Posted 22 December 2010 - 03:03 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.

#8 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

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 WannaFly

WannaFly

    Member

  • Members
  • PipPip
  • 17 posts

Posted 22 December 2010 - 03:28 AM

Chris: Thanks, I'm reading about that now. Is this correct then? You should use about a 110Ohm resistor to supply about 35mA if the LED is connected to 3.3V? I = R / V I = 110 / 3.3 I = 33.3mA Is that the correct thinking? If so where does the 8mA from the pin come in?

#10 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

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 ClosedEyesSeeing

ClosedEyesSeeing

    Member

  • Members
  • PipPip
  • 21 posts
  • LocationVirginia

Posted 22 December 2010 - 05:29 AM

Alright, I think I've got this licked better now. PWM was apparently not a very good idea, so I ran the switch leg to A5 and the results are far superior. Plus, it helped make the code smaller. :)

    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

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.