peony3000

Gadgeteer_DD01_Led_Joystick_Conditional_01

Feb 11th, 2013
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.20 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Threading;
  4. using Microsoft.SPOT;
  5. using Microsoft.SPOT.Presentation;
  6. using Microsoft.SPOT.Presentation.Controls;
  7. using Microsoft.SPOT.Presentation.Media;
  8. using Microsoft.SPOT.Touch;
  9.  
  10. using Gadgeteer.Networking;
  11. using GT = Gadgeteer;
  12. using GTM = Gadgeteer.Modules;
  13. using Gadgeteer.Modules.GHIElectronics;
  14.  
  15. namespace Gadgeteer_DD01_Led_Joystick_Conditional_01
  16. {
  17.     public partial class Program
  18.     {
  19.         // variables that are visible "Program" wide go here
  20.  
  21.         // create a timer robot that ticks every 100 milliseconds
  22.         GT.Timer timer = new GT.Timer(100);
  23.  
  24.         // This method is run when the mainboard is powered up or reset.  
  25.         void ProgramStarted()
  26.         {
  27.             /*******************************************************************************************
  28.             Modules added in the Program.gadgeteer designer view are used by typing
  29.             their name followed by a period, e.g.  button.  or  camera.
  30.            
  31.             Many modules generate useful events. Type +=<tab><tab> to add a handler to an event, e.g.:
  32.                 button.ButtonPressed +=<tab><tab>
  33.            
  34.             If you want to do something periodically, use a GT.Timer and handle its Tick event, e.g.:
  35.                 GT.Timer timer = new GT.Timer(1000); // every second (1000ms)
  36.                 timer.Tick +=<tab><tab>
  37.                 timer.Start();
  38.             *******************************************************************************************/
  39.  
  40.             //  create a timer event handler robot that notices when the timer has ticked
  41.             timer.Tick += new GT.Timer.TickEventHandler(timer_Tick);
  42.  
  43.             // start the timer robot running
  44.             timer.Start();
  45.  
  46.             // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
  47.             Debug.Print("Program Started");
  48.         }
  49.  
  50.         void timer_Tick(GT.Timer timer)
  51.         {
  52.             // the timer has ticked
  53.  
  54.             // look at the joystick and get it's position
  55.             // assign the x-direction from 0 to 1 to the variable holder joystickPosX
  56.             double joystickPosX = joystick.GetJoystickPosition().X;
  57.  
  58.             // assign the y-direction from 0 to 1 to the variable holder joystickPosY
  59.             double joystickPosY = joystick.GetJoystickPosition().Y;
  60.  
  61.             // the joystick values range from 0 - 1
  62.             // print the readings to the debug output window
  63.             Debug.Print("X = " + joystickPosX + " Y = " + joystickPosY);
  64.  
  65.             // create a conditional statement
  66.             // check to see if the joystick is roughly in the middle
  67.             if (joystickPosX > 0.4 && joystickPosX < 0.6 && joystickPosY > 0.4 && joystickPosY < 0.6)
  68.             {
  69.                 multicolorLed.TurnRed();
  70.             }
  71.             else
  72.             {
  73.                 multicolorLed.TurnOff();
  74.             }
  75.         }
  76.     }
  77. }
  78.  
  79. // alternatives
  80.  
  81. // use the OR || statement instead of the AND && statement
  82.  
  83. // use green but you might find a bug
  84. // tell the gadgeteer that the green and blue are incorrectly swapped over
  85. //multicolorLed.GreenBlueSwapped = true;
Advertisement
Add Comment
Please, Sign In to add comment