peony3000

Gadgeteer_DD01_LED_Button_01

Feb 11th, 2013
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.54 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Threading;
  4. using Microsoft.SPOT;
  5. using Microsoft.SPOT.Presentation;
  6. using Microsoft.SPOT.Presentation.Controls;
  7. using Microsoft.SPOT.Presentation.Media;
  8. using Microsoft.SPOT.Touch;
  9.  
  10. using Gadgeteer.Networking;
  11. using GT = Gadgeteer;
  12. using GTM = Gadgeteer.Modules;
  13. using Gadgeteer.Modules.GHIElectronics;
  14.  
  15. namespace Gadgeteer_DD01_LED_Button_01
  16. {
  17.     public partial class Program
  18.     {
  19.         // This method is run when the mainboard is powered up or reset.  
  20.         void ProgramStarted()
  21.         {
  22.             /*******************************************************************************************
  23.             Modules added in the Program.gadgeteer designer view are used by typing
  24.             their name followed by a period, e.g.  button.  or  camera.
  25.            
  26.             Many modules generate useful events. Type +=<tab><tab> to add a handler to an event, e.g.:
  27.                 button.ButtonPressed +=<tab><tab>
  28.            
  29.             If you want to do something periodically, use a GT.Timer and handle its Tick event, e.g.:
  30.                 GT.Timer timer = new GT.Timer(1000); // every second (1000ms)
  31.                 timer.Tick +=<tab><tab>
  32.                 timer.Start();
  33.             *******************************************************************************************/
  34.  
  35.             // create an event handler robot that notices when the button is pressed
  36.             button.ButtonPressed += new Button.ButtonEventHandler(button_ButtonPressed);
  37.  
  38.             // create an event handler robot that notices when the button is released
  39.             button.ButtonReleased += new Button.ButtonEventHandler(button_ButtonReleased);
  40.  
  41.             // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
  42.             Debug.Print("Program Started");
  43.         }
  44.  
  45.         // this method is what happens when the event handler robot notices that the button has been released
  46.         void button_ButtonReleased(Button sender, Button.ButtonState state)
  47.         {
  48.             // tell the multicolor LED to turn off
  49.             multicolorLed.TurnOff();
  50.         }
  51.  
  52.         // this method is what happens when the event handler robot notices that the button has been pressed
  53.         void button_ButtonPressed(Button sender, Button.ButtonState state)
  54.         {
  55.             // tell the multicolor LED to turn green
  56.             multicolorLed.TurnGreen();
  57.         }
  58.     }
  59. }
  60.  
  61. // aternatives
  62.  
  63. // turn the button led on and off
  64. //button.TurnLEDOn();
Advertisement
Add Comment
Please, Sign In to add comment