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_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 boolean to act as an on/off switch
- bool ledOn;
- // 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();
- // set the ledOn switch to false to show that it is off
- ledOn = false;
- // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
- Debug.Print("Program Started");
- }
- void timer_Tick(GT.Timer timer)
- {
- // the timer has ticked!
- // check if the switch is true or false
- if (ledOn == true)
- {
- // if boolean ledOn is true then the multicolorLed is on
- // make the led off
- multicolorLed.TurnOff();
- // make a note that the multicolorLed is off by setting ledOn to false
- ledOn = false;
- }
- else
- {
- // if boolean ledOn is false then the multicolorLed is off
- // make the led turn on to the color red
- multicolorLed.TurnRed();
- // make a note that the multicolorLed is on by setting ledOn to true
- ledOn = true;
- }
- // end of the timer method
- }
- }
- }
- // alternatives
- // use green but you might find a bug
- // tell the gadgeteer that the green and blue are incorrectly swapped over
- //multicolorLed.GreenBlueSwapped = true;
- // flip the boolean counter to the opposite state
- //ledOn = !ledOn;
- // ask the led what color it is
- //if (multicolorLed.GetCurrentColor() == GT.Color.Green)
- //{
- // multicolorLed.TurnOff();
- //}
- //else if(ledOn = false)
Advertisement
Add Comment
Please, Sign In to add comment