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_Joystick_Transition_01
- {
- public partial class Program
- {
- // variables that are visible "Program" wide go here
- // create a timer robot that ticks every 100 milliseconds
- GT.Timer timer = new GT.Timer(100);
- // variable holder for the current X position color
- int currentColorX;
- // variable holder for the current Y position color
- int currentColorY;
- // variable holder for the previous X position color
- int previousColorX;
- // variable holder for the previous Y position color
- int previousColorY;
- // variable holder for the speed of transition
- int transitionValue = 10;
- // 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)
- {
- // the timer robot has ticked
- // look at the joystick and get it's position
- // assign the x-direction from 0 to 1 to the variable holder joystickPosX
- double joystickPosX = joystick.GetJoystickPosition().X;
- // assign the y-direction from 0 to 1 to the variable holder joystickPosY
- double joystickPosY = joystick.GetJoystickPosition().Y;
- // the joystick values range from 0 - 1
- // print the readings to the debug output window
- Debug.Print("X = " + joystickPosX + " Y = " + joystickPosY);
- // find the difference between the target value from the joystick and the previous value
- // subtract the difference from the previous value
- // if the value is negative it will be subtracted
- // you have to convert the joystick's position into a bigger value
- currentColorX = previousColorX - ((previousColorX - (int)(joystickPosX * 255)) / transitionValue);
- // find the difference between the target value from the joystick and the previous value
- // subtract the difference from the previous value
- // if the value is negative it will be subtracted
- // you have to convert the joystick's position into a bigger value
- currentColorY = previousColorY - ((previousColorY - (int)(joystickPosY * 255)) / transitionValue);
- // print to the debug output window
- Debug.Print("X color = " + currentColorX + " Y color = " + currentColorY);
- // assign the x value to blue
- multicolorLed.SetBlueIntensity(currentColorX);
- // assign the y value to red
- multicolorLed.SetRedIntensity(currentColorY);
- // save the current values away so we can use it next time the timer ticks
- previousColorX = currentColorX;
- previousColorY = currentColorY;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment