Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Threading;
- using Microsoft.SPOT;
- using Microsoft.SPOT.Presentation;
- using Microsoft.SPOT.Presentation.Controls;
- using Microsoft.SPOT.Presentation.Media;
- using Microsoft.SPOT.Touch;
- using Gadgeteer.Networking;
- using GT = Gadgeteer;
- using GTM = Gadgeteer.Modules;
- using Gadgeteer.Modules.GHIElectronics;
- namespace Gadgeteer_DD01_Led_Timer_Random_01
- {
- public partial class Program
- {
- // variables that are visible "Program" wide go here
- // create a timer robot that ticks every 1000 milliseconds
- GT.Timer timer = new GT.Timer(1000);
- // create a random number generator robot for setting the color value
- Random randomGenerator = new Random();
- // create a variable holder to hold the random number generated
- int randomNumber;
- // This method is run when the mainboard is powered up or reset.
- void ProgramStarted()
- {
- /*******************************************************************************************
- Modules added in the Program.gadgeteer designer view are used by typing
- their name followed by a period, e.g. button. or camera.
- Many modules generate useful events. Type +=<tab><tab> to add a handler to an event, e.g.:
- button.ButtonPressed +=<tab><tab>
- If you want to do something periodically, use a GT.Timer and handle its Tick event, e.g.:
- GT.Timer timer = new GT.Timer(1000); // every second (1000ms)
- timer.Tick +=<tab><tab>
- timer.Start();
- *******************************************************************************************/
- // create a timer event handler robot that notices when the timer has ticked
- timer.Tick += new GT.Timer.TickEventHandler(timer_Tick);
- // start the timer robot running
- timer.Start();
- // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
- Debug.Print("Program Started");
- }
- void timer_Tick(GT.Timer timer)
- {
- // use the random number generator to create a value between 0 and 255
- randomNumber = randomGenerator.Next(255);
- // print to the debug output window of the computer
- Debug.Print("Random number = "+randomNumber);
- // set the color value to the random number value
- multicolorLed.SetRedIntensity(randomNumber);
- // use the random number generator to create another value
- // set a differnt color value to the random number value
- }
- }
- }
- // alternatives
- //if (randomNumber < 64)
- //{
- // // if the condition is true
- // // miss a go by not doing anything
- //}
- //else
- //{
- // // if the condition isn't true
- // // do the color change
- //}
Advertisement
Add Comment
Please, Sign In to add comment