Created
April 19, 2012 05:46
-
-
Save ChrisHammond/2418912 to your computer and use it in GitHub Desktop.
This code takes 4 different Netduino Go! Modules and flashes 3 LED RGBs based on the potentiometer. For a full description visit the blog post at * http://www.chrishammond.com/blog/itemid/2499/simple-netduino-go-tutorial-flashing-rgb-leds-with.aspx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Project References include GoBux, Microsoft.SPOT.Graphics, Microsoft.SPOT.Native, mscorlib, NetduinoGo.Button, NetduinoGo.Potentiometer, NetduinoGo.RgbLed | |
* This code takes 4 different Netduino Go! Modules and flashes 3 LED RGBs based on the potentiometer. For a full description visit the blog post at | |
* http://www.chrishammond.com/blog/itemid/2499/simple-netduino-go-tutorial-flashing-rgb-leds-with.aspx | |
* | |
* 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 | |
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 | |
} | |
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); | |
} | |
//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