Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChrisHammond/2419111 to your computer and use it in GitHub Desktop.
Save ChrisHammond/2419111 to your computer and use it in GitHub Desktop.
Flashing 4 RGB Led Modules on a Netduino Go! in sequence
/*
* Project References include GoBux, Microsoft.SPOT.Graphics, Microsoft.SPOT.Native, mscorlib, NetduinoGo.Button, NetduinoGo.Potentiometer, NetduinoGo.RgbLed
* This code takes 6 different Netduino Go! Modules and flashes 4 LED RGBs based on the potentiometer.
* You can find the video sample for this at http://www.youtube.com/watch?v=EH6uc324aY8
*
* Feel free to modify/fork this code, no attribution necessary, but it would be appreciated.
* Chris Hammond (http://www.chrishammond.com) @christoc
*/
using NetduinoGo;
using SecretLabs.NETMF.Hardware.NetduinoGo;
namespace NG1
{
public class Program
{
//code based on http://forums.netduino.com/index.php?/topic/3933-early-getting-started-with-netduino-go-software-and-instructions/
static readonly Button OnButton = new Button(GoSockets.Socket1); // this button will start/stop the flashing
static readonly RgbLed RedLed = new RgbLed(GoSockets.Socket2); // this is the socket for the first LED
static readonly RgbLed GreenLed = new RgbLed(GoSockets.Socket3); // this is the socket for the second LED
static readonly RgbLed BlueLed = new RgbLed(GoSockets.Socket4); // this is the socket for the third LED
static readonly RgbLed RandomLed = new RgbLed(GoSockets.Socket5); // this is the socket for the fourth LED
public static bool CurrentState; // keep track of if the button was pressed to turn it on, or off
static Potentiometer pt = new Potentiometer(GoSockets.Socket6); // the potentiometer to control the speed of the LEDs
public static void Main()
{
OnButton.ButtonReleased += ButtonButtonReleased; // setup the button handler
CurrentState = false; //make sure we start with it off
while (true) //we're using a device, it will never end
{
if (CurrentState) // see if we should be displaying the LEDs or not
{
RedLed.SetColor(255, 0, 0); // turn on the red LED
System.Threading.Thread.Sleep((int)(100 * pt.GetValue())); // pause for a moment based on the potentiometer state
AllOff(); // turn off all LEDs
GreenLed.SetColor(0, 255, 0); // turn on the green LED
System.Threading.Thread.Sleep((int)(100 * pt.GetValue())); // pause for a moment based on the potentiometer state
AllOff(); // turn off all LEDs
BlueLed.SetColor(0, 0, 255); // turn on the blue LED
System.Threading.Thread.Sleep((int)(100 * pt.GetValue())); // pause for a moment based on the potentiometer state
AllOff(); // turn off all LEDs
RandomLed.SetColor(255, 255, 255); // turn on the random LED to white
System.Threading.Thread.Sleep((int)(100 * pt.GetValue())); // pause for a moment based on the potentiometer state
AllOff(); // turn off all LEDs
BlueLed.SetColor(0, 0, 255); // turn on the blue LED
System.Threading.Thread.Sleep((int)(100 * pt.GetValue())); // pause for a moment based on the potentiometer state
AllOff(); // turn off all LEDs
GreenLed.SetColor(0, 255, 0); // turn on the green LED
System.Threading.Thread.Sleep((int)(100 * pt.GetValue())); // pause for a moment based on the potentiometer state
AllOff(); // turn off all LEDs
}
else
{
AllOff();
}
}
}
//method to turn off all the LEDs
static void AllOff()
{
RedLed.SetColor(0, 0, 0);
GreenLed.SetColor(0, 0, 0);
BlueLed.SetColor(0, 0, 0);
RandomLed.SetColor(0, 0, 0);
}
//button handler
static void ButtonButtonReleased(object sender, bool buttonState)
{
CurrentState = !CurrentState; //set the state to the opposite of whatever we were before
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment