Buenas
today’s example is a little more complicated than a Hello World, but you gives more joys. It’s used a button and a multi-color LED to change the color of it with a timer.
In this example we will use
- Fez Spider Mainboard
http://savecomm.net/p/53/fez-spider-starter-kit - USB Client DP
http://www.netmf.com/showcase.aspx?ShowcaseID=1 & id = 110 - Smart Multi Color Led Module
http://www.ghielectronics.com/catalog/product/272 - Button Module
http://www.ghielectronics.com/catalog/product/274
with the following diagram
And again, with less than 50 lines of code source we can deploy our application.
1: using Gadgeteer.Modules.GHIElectronics;
2: using GT = Gadgeteer;
3:
4: namespace GadgeteerApp5
5: {
6: public partial class Program
7: {
8: private GT.Timer _timer;
9:
10: void ProgramStarted()
11: {
12: button.ButtonPressed += ButtonButtonPressed;
13: _timer = new GT.Timer(1000);
14: _timer.Tick += TimerTick;
15: }
16:
17: void ButtonButtonPressed(Button sender, Button.ButtonState state)
18: {
19: if (!_timer.IsRunning)
20: {
21: _timer.Start();
22: }
23: else
24: {
25: _timer.Stop();
26: multicolorLed.TurnOff();
27: }
28: }
29:
30: private void TimerTick(GT.Timer timer)
31: {
32: var color = multicolorLed.GetCurrentColor();
33:
34: if (color == GT.Color.Blue)
35: {
36: color = GT.Color.Green;
37: }
38: else if (color == GT.Color.Green)
39: {
40: color = GT.Color.Red;
41: }
42: else
43: {
44: color = GT.Color.Blue;
45: }
46:
47: multicolorLed.TurnColor(color);
48: }
49: }
50: }
Interesting application data
- Line 13, special implementation of timer for.Net Gadgeteer. Or try to use the timer of. Net, you will die between terrible suffering
- Line 19, in the implementation of the button, the Timer starts and shuts off the LED when the timer is stopped
- Line 29, shows how simple that is to use LEDs, a GetCurrentColor() to get the current color and then a TurnColor() to set the color of the LED
The video http://www.youtube.com/watch?feature=player_embedded&v=yEwqQTdRc2c
Saludos @ La Finca
El Bruno
Leave a comment