peony3000

Gadgeteer_DD01_Led_Timer_Random_01

Feb 11th, 2013
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.99 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_Random_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 random number generator robot for setting the color value
  25.         Random randomGenerator = new Random();
  26.  
  27.         // create a variable holder to hold the random number generated
  28.         int randomNumber;
  29.  
  30.         // This method is run when the mainboard is powered up or reset.  
  31.         void ProgramStarted()
  32.         {
  33.             /*******************************************************************************************
  34.             Modules added in the Program.gadgeteer designer view are used by typing
  35.             their name followed by a period, e.g.  button.  or  camera.
  36.            
  37.             Many modules generate useful events. Type +=<tab><tab> to add a handler to an event, e.g.:
  38.                 button.ButtonPressed +=<tab><tab>
  39.            
  40.             If you want to do something periodically, use a GT.Timer and handle its Tick event, e.g.:
  41.                 GT.Timer timer = new GT.Timer(1000); // every second (1000ms)
  42.                 timer.Tick +=<tab><tab>
  43.                 timer.Start();
  44.             *******************************************************************************************/
  45.  
  46.             //  create a timer event handler robot that notices when the timer has ticked
  47.             timer.Tick += new GT.Timer.TickEventHandler(timer_Tick);
  48.  
  49.             // start the timer robot running
  50.             timer.Start();
  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.            
  59.             // use the random number generator to create a value between 0 and 255        
  60.             randomNumber = randomGenerator.Next(255);
  61.  
  62.             // print to the debug output window of the computer
  63.             Debug.Print("Random number = "+randomNumber);
  64.  
  65.             // set the color value to the random number value
  66.             multicolorLed.SetRedIntensity(randomNumber);
  67.  
  68.             // use the random number generator to create another value            
  69.             // set a differnt color value to the random number value
  70.  
  71.         }
  72.     }
  73. }
  74.  
  75. // alternatives
  76.  
  77. //if (randomNumber < 64)
  78. //{
  79. //    // if the condition is true
  80. //    // miss a go by not doing anything
  81. //}
  82. //else
  83. //{
  84. //    // if the condition isn't true
  85. //    // do the color change
  86. //}
Advertisement
Add Comment
Please, Sign In to add comment