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_Conditional_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);
- // 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 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);
- // create a conditional statement
- // check to see if the joystick is roughly in the middle
- if (joystickPosX > 0.4 && joystickPosX < 0.6 && joystickPosY > 0.4 && joystickPosY < 0.6)
- {
- multicolorLed.TurnRed();
- }
- else
- {
- multicolorLed.TurnOff();
- }
- }
- }
- }
- // alternatives
- // use the OR || statement instead of the AND && statement
- // use green but you might find a bug
- // tell the gadgeteer that the green and blue are incorrectly swapped over
- //multicolorLed.GreenBlueSwapped = true;
Advertisement
Add Comment
Please, Sign In to add comment