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

Minding an RGB Led via external logic


  • Please log in to reply
3 replies to this topic

#1 Dr Who

Dr Who

    Advanced Member

  • Members
  • PipPipPip
  • 261 posts
  • LocationNYC

Posted 03 November 2012 - 03:59 AM

Hello!
I've been turning over a few ideas regarding how to manage the RGB LED types we use. The code as supplied via this website, and seen inside the book on Netduinos most of us have read provided me with the clews to get these devices showed me how to step through color changes. The button one and even the blinking LED one, (not used in the code) provided other clews. However this is as far as I've gotten with convincing (or confusing) an RGB LED to change its colors via logic.
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoMini;

namespace Test74
{
    public class Program
    {
        public static void Main()
        {
            // write your code here
            PWM redLed = new PWM(Pins.GPIO_PIN_20);
            PWM greenLed = new PWM(Pins.GPIO_PIN_19);
            PWM blueLed = new PWM(Pins.GPIO_PIN_18);

            // change the color intensities
            redLed.SetDutyCycle(60);    // 60% red intensity
            greenLed.SetDutyCycle(2);   // 0% green intensity
            blueLed.SetDutyCycle(100); // 100% blue intensity

            

            // go to sleep
            Thread.Sleep(350);

              // write your code here
       	
            OutputPort led = new OutputPort(Pins.GPIO_PIN_17, false);
            Thread.Sleep(350);
            InputPort button = new InputPort(Pins.GPIO_PIN_16, false, Port.ResistorMode.Disabled);
            bool buttonState = false;
            Thread.Sleep(350);
            while (true)
            {
                buttonState = button.Read();
                led.Write(!buttonState);
            }
     	
         	// change the color intensities
            redLed.SetDutyCycle(0);    // 60% red intensity
            greenLed.SetDutyCycle(75);   // 0% green intensity
            blueLed.SetDutyCycle(0); // 100% blue intensity

            // go to sleep
            Thread.Sleep(350);
        }

    }
}
What I want to happen is that the block of code after the button event would accept two bit streams as inputs via specific GPIOs and then cause a color change to continue along further. Part of the problem is that I confess that I really do not understand C Sharp as well as I should. It happens.

Edited by Dr Who, 03 November 2012 - 03:59 AM.


Doctor Who
"This signature does not exist!"

#2 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 03 November 2012 - 12:38 PM

the codeblock after the while loop never gets excecuted. lets assume you know how to read your gpio bitstream, after youve done that you call an function like: void ChangeLedColor(Single r, Single b, Single g) /assuming you use the microsoft pwm { redLEd.DutyCylce = r; ... ... }

#3 Dr Who

Dr Who

    Advanced Member

  • Members
  • PipPipPip
  • 261 posts
  • LocationNYC

Posted 05 November 2012 - 03:49 PM

the codeblock after the while loop never gets excecuted.

lets assume you know how to read your gpio bitstream, after youve done that you call an function like:

void ChangeLedColor(Single r, Single b, Single g) /assuming you use the microsoft pwm
{
redLEd.DutyCylce = r;
...
...
}



Hello!
I have since decided not to use the button function to pass data into the system via the PAL16L8. Logic will be receive its data via more logic, and thence the PAL part will send data into the Mini and then the code will take it from there. And that's the sticking point. That of writing the code to understand the data streaming out from the PAL part and interpret into the code that the RGB needs. Because of how C Sharp works it should be easier to write it out. How? I'm not sure.


Doctor Who
"This signature does not exist!"

#4 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 05 November 2012 - 08:03 PM

i am not sure if this will work well. i am also not sure if i understand exactly what you wanna do. you programm that chip, it switches it outputs to whatever you programm it todo when something happens ? you could than use an interrupt if data is ready, and when that interrupt occurs read all the other data pins. it will use a lot of pins. maybe you want to use another chip? pcf8574 are nice chips for input. they offer up to 8 inputs and interrupt functionmality. they are i2c and just use 2 pins (+1 interrupt, thats nice cos you dont have to poll the data alle the time)




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.