peony3000

Gadgeteer_DD01_LED_Timer_01

Feb 11th, 2013
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.37 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_Timer_01
  16. {
  17.     public partial class Program
  18.     {
  19.         // variables that are visible "Program" wide go here
  20.  
  21.         // create a timer robot that ticks every 1000 milliseconds
  22.         GT.Timer timer = new GT.Timer(1000);
  23.  
  24.         // create a boolean to act as an on/off switch
  25.         bool ledOn;
  26.  
  27.         // This method is run when the mainboard is powered up or reset.  
  28.         void ProgramStarted()
  29.         {
  30.             /*******************************************************************************************
  31.             Modules added in the Program.gadgeteer designer view are used by typing
  32.             their name followed by a period, e.g.  button.  or  camera.
  33.            
  34.             Many modules generate useful events. Type +=<tab><tab> to add a handler to an event, e.g.:
  35.                 button.ButtonPressed +=<tab><tab>
  36.            
  37.             If you want to do something periodically, use a GT.Timer and handle its Tick event, e.g.:
  38.                 GT.Timer timer = new GT.Timer(1000); // every second (1000ms)
  39.                 timer.Tick +=<tab><tab>
  40.                 timer.Start();
  41.             *******************************************************************************************/
  42.  
  43.             //  create a timer event handler robot that notices when the timer has ticked
  44.             timer.Tick += new GT.Timer.TickEventHandler(timer_Tick);
  45.  
  46.             // start the timer robot running
  47.             timer.Start();
  48.  
  49.             // set the ledOn switch to false to show that it is off
  50.             ledOn = false;
  51.  
  52.             // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
  53.             Debug.Print("Program Started");
  54.         }
  55.  
  56.         void timer_Tick(GT.Timer timer)
  57.         {
  58.             // the timer has ticked!
  59.  
  60.             // check if the switch is true or false
  61.             if (ledOn == true)
  62.             {
  63.                 // if boolean ledOn is true then the multicolorLed is on
  64.  
  65.                 // make the led off
  66.                 multicolorLed.TurnOff();
  67.  
  68.                 // make a note that the multicolorLed is off by setting ledOn to false
  69.                 ledOn = false;
  70.             }
  71.             else
  72.             {
  73.                 // if boolean ledOn is false then the multicolorLed is off
  74.  
  75.                 // make the led turn on to the color red
  76.                 multicolorLed.TurnRed();
  77.  
  78.                 // make a note that the multicolorLed is on by setting ledOn to true
  79.                 ledOn = true;
  80.  
  81.             }
  82.  
  83.             // end of the timer method
  84.         }
  85.     }
  86. }
  87.  
  88. // alternatives
  89.  
  90. // use green but you might find a bug
  91. // tell the gadgeteer that the green and blue are incorrectly swapped over
  92. //multicolorLed.GreenBlueSwapped = true;
  93.  
  94. // flip the boolean counter to the opposite state
  95. //ledOn = !ledOn;
  96.  
  97. // ask the led what color it is
  98. //if (multicolorLed.GetCurrentColor() == GT.Color.Green)
  99. //{
  100. //    multicolorLed.TurnOff();
  101. //}
  102.  
  103. //else if(ledOn = false)
Advertisement
Add Comment
Please, Sign In to add comment