Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- 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_Joystick_Blink_01
- {
- public partial class Program
- {
- // Variable holders that are available everywhere
- TimeSpan blinkTick = new TimeSpan(0, 0, 0, 0, 1000);
- TimeSpan ledBlinkLength = new TimeSpan(0, 0, 0, 0, 100); // create a timebased variable holder for the length of the blinks
- int ledBlinkOffset = 500;
- //int ledBlinkSpace = (250);
- TimeSpan led1BlinkLength = new TimeSpan(0, 0, 0, 0, 100); // create a timebased variable holder for the length of the blinks
- int led1BlinkOffset = 500;
- //int led1BlinkSpace = (250);
- // This method is run when the mainboard is powered up or reset.
- GT.Timer timer = new GT.Timer(1000, GT.Timer.BehaviorType.RunContinuously);
- 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();
- *******************************************************************************************/
- // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
- Debug.Print("Program Started");
- timer.Tick += new GT.Timer.TickEventHandler(timer_Tick);
- timer.Start();
- joystick.DebugPrintEnabled = true; // allow the program to ask the joystick questions
- }
- void timer_Tick(GT.Timer timer)
- {
- // this is what the event handling robot will do when it sees an event
- //look at the joystick
- double joystickPosX = joystick.GetJoystickPostion().X; // assigns the x-direction from 0 to 1 to the variable holder joystickPosX
- double joystickPosY = joystick.GetJoystickPostion().Y; // assigns the y-direction from 0 to 1 to the variable holder joystickPosY
- //Debug.Print(((int)(joystickPosX * 1000)).ToString()); // prints the current joystick position * 255 in the x-direction
- //Debug.Print(((int)(joystickPosY * 1000)).ToString()); // prints the current joystick position * 255 in the y-direction
- //ledBlinkOffset = TimeSpan.FromTicks((100 + (int)(joystickPosX * 800)) * 1000);
- ledBlinkOffset = (100 + (int)(joystickPosX * 800));
- led1BlinkOffset = 1000 - ledBlinkOffset;
- GT.Timer ledTimer = new GT.Timer(ledBlinkOffset, GT.Timer.BehaviorType.RunOnce);
- ledTimer.Tick += new GT.Timer.TickEventHandler(ledTimer_Tick);
- GT.Timer led1Timer = new GT.Timer(led1BlinkOffset, GT.Timer.BehaviorType.RunOnce);
- led1Timer.Tick += new GT.Timer.TickEventHandler(led1timer_Tick);
- ledTimer.Start();
- led1Timer.Start();
- }
- void led1timer_Tick(GT.Timer timer)
- {
- //led1.BlinkOnce(GT.Color.Red, led1BlinkLength);
- led1.SetRedIntensity(255);
- //Thread.Sleep(100);
- led1.SetRedIntensity(0);
- timer.Stop();
- }
- void ledTimer_Tick(GT.Timer timer)
- {
- //led.BlinkOnce(GT.Color.Red, ledBlinkLength);
- led.SetRedIntensity(255);
- //Thread.Sleep(100);
- led.SetRedIntensity(0);
- timer.Stop();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment