peony3000

Gadgeteer_DD01_Led_Joystick_01

Feb 11th, 2013
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.15 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_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 1000 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 robot 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.             // convert the joystick's X position into a bigger value useful for color
  66.             int ledColorX = (int)(joystickPosX * 255);
  67.  
  68.             // convert the joystick's Y position into a bigger value useful for color
  69.             int ledColorY = (int)(joystickPosY * 255);
  70.  
  71.             // assign the x value to blue
  72.             multicolorLed.SetBlueIntensity(ledColorX);
  73.  
  74.             // assign the y value to red
  75.             multicolorLed.SetRedIntensity(ledColorY);
  76.  
  77.         }
  78.     }
  79. }
  80.  
  81. // alternatives
  82.  
  83. // put the variables in the 'right' places
Advertisement
Add Comment
Please, Sign In to add comment