peony3000

Gadgeteer Joystick Junk

Mar 29th, 2012
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.05 KB | None | 0 0
  1. using System;
  2. using System.Threading;
  3. using Microsoft.SPOT;
  4. using Microsoft.SPOT.Presentation;
  5. using Microsoft.SPOT.Presentation.Controls;
  6. using Microsoft.SPOT.Presentation.Media;
  7. using Microsoft.SPOT.Touch;
  8.  
  9. using Gadgeteer.Networking;
  10. using GT = Gadgeteer;
  11. using GTM = Gadgeteer.Modules;
  12. using Gadgeteer.Modules.GHIElectronics;
  13.  
  14. namespace Gadgeteer_Navigator_01
  15. {
  16.     public partial class Program
  17.     {
  18.         // Variable holders that are available everywhere
  19.         int blinkTick = (1000);
  20.         //int ledBlinkLength = (250); // create a timebased variable holder for the length of the blinks
  21.         int ledBlinkOffset = (5);
  22.         //int ledBlinkSpace = (250);
  23.         //int led1BlinkLength = (250); // create a timebased variable holder for the length of the blinks
  24.         int led1BlinkOffset = (5);
  25.         //int led1BlinkSpace = (250);
  26.  
  27.         Boolean[] ledBlinkCondition = new Boolean[11];
  28.         Boolean[] led1BlinkCondition = new Boolean[11];
  29.  
  30.         // This method is run when the mainboard is powered up or reset.  
  31.         void ProgramStarted()
  32.         {
  33.             /*******************************************************************************************
  34.             Modules added in the Program.gadgeteer designer view are used by typing
  35.             their name followed by a period, e.g.  button.  or  camera.
  36.            
  37.             Many modules generate useful events. Type +=<tab><tab> to add a handler to an event, e.g.:
  38.                 button.ButtonPressed +=<tab><tab>
  39.            
  40.             If you want to do something periodically, use a GT.Timer and handle its Tick event, e.g.:
  41.                 GT.Timer timer = new GT.Timer(1000); // every second (1000ms)
  42.                 timer.Tick +=<tab><tab>
  43.                 timer.Start();
  44.             *******************************************************************************************/
  45.  
  46.  
  47.             // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
  48.             Debug.Print("Program Started");
  49.  
  50.             GT.Timer timer = new GT.Timer(blinkTick); // create a tick event every tenth of a second
  51.             timer.Tick += new GT.Timer.TickEventHandler(timer_Tick); // create an event handling robot to watch for the tick
  52.             timer.Start(); // start the timer
  53.  
  54.             joystick.DebugPrintEnabled = true; // allow the program to ask the joystick questions
  55.         }
  56.  
  57.         void timer_Tick(GT.Timer timer)
  58.         {
  59.  
  60.             // this is what the event handling robot will do when it sees an event
  61.             //look at the joystick
  62.             double joystickPosX = joystick.GetJoystickPostion().X; // assigns the x-direction from 0 to 1 to the variable holder joystickPosX
  63.             double joystickPosY = joystick.GetJoystickPostion().Y; // assigns the y-direction from 0 to 1 to the variable holder joystickPosY
  64.             //Debug.Print(((int)(joystickPosX * 1000)).ToString()); // prints the current joystick position * 255 in the x-direction
  65.             //Debug.Print(((int)(joystickPosY * 1000)).ToString()); // prints the current joystick position * 255 in the y-direction
  66.  
  67.             for (int increment03 = 0; increment03 < 10; increment03++)
  68.             {
  69.                 ledBlinkCondition[increment03] = false;
  70.                 led1BlinkCondition[increment03] = false;
  71.             }
  72.            
  73.             ledBlinkOffset = ((int)(joystickPosX * 10))-1;
  74.             led1BlinkOffset = 9 - ledBlinkOffset;
  75.  
  76.             Debug.Print("0 " + ledBlinkOffset.ToString());
  77.             Debug.Print("1 " + led1BlinkOffset.ToString());
  78.  
  79.             ledBlinkCondition[ledBlinkOffset] = true;
  80.  
  81.             led1BlinkCondition[led1BlinkOffset] = true;
  82.  
  83.            
  84.             for (int increment02 = 0;  increment02 < 10; increment02++)
  85.             {
  86.                 // create a blink offset
  87.                 if (ledBlinkCondition[increment02])
  88.                 {
  89.                     led.SetRedIntensity(255);
  90.                 }
  91.                 else
  92.                 {
  93.                     led.SetRedIntensity(0);
  94.                 }
  95.                 if (led1BlinkCondition[increment02])
  96.                 {
  97.                     led1.SetRedIntensity(255);
  98.                 }
  99.                 else
  100.                 {
  101.                     led1.SetRedIntensity(0);
  102.                 }
  103.                 Thread.Sleep(100);
  104.             }
  105.  
  106.          
  107.            
  108.  
  109.             //ledBlinkOffset = ((int)(joystickPosX * 8)); // sets the led brightness to the current joystick position * 255 in the x-direction
  110.             //led1BlinkOffset = 800 - ledBlinkOffset; // sets the led brightness to the current joystick position * 255 in the y-direction
  111.             //Debug.Print(ledBlinkOffset.ToString());
  112.             //Debug.Print(led1BlinkOffset.ToString());
  113.             //ledBlinkLength = ((int)(joystickPosY * 1)); // sets the led brightness to the current joystick position * 255 in the x-direction
  114.             //led1BlinkLength = ledBlinkLength; // sets the led brightness to the current joystick position * 255 in the x-direction
  115.             //ledBlinkSpace = (blinkTick - ledBlinkOffset - (ledBlinkLength * 2));
  116.             //led1BlinkSpace = (blinkTick - led1BlinkOffset - (led1BlinkLength * 2));
  117.  
  118.            
  119.             //led1Blink();
  120.             //ledBlink();
  121.        
  122.         }
  123.  
  124.         /*void ledBlink ()
  125.         {
  126.             Thread.Sleep(ledBlinkOffset);
  127.             led.SetRedIntensity(255);
  128.             Thread.Sleep(ledBlinkLength);
  129.             led.SetRedIntensity(0);
  130.             Thread.Sleep(ledBlinkSpace);
  131.             led.SetRedIntensity(255);
  132.             Thread.Sleep(ledBlinkLength);
  133.             led.SetRedIntensity(0);
  134.         }
  135.  
  136.         void led1Blink()
  137.         {
  138.             Thread.Sleep(led1BlinkOffset);
  139.             led1.SetRedIntensity(255);
  140.             Thread.Sleep(led1BlinkLength);
  141.             led1.SetRedIntensity(0);
  142.             Thread.Sleep(led1BlinkSpace);
  143.             led1.SetRedIntensity(255);
  144.             Thread.Sleep(led1BlinkLength);
  145.             led1.SetRedIntensity(0);
  146.         }*/
  147.     }
  148. }
Advertisement
Add Comment
Please, Sign In to add comment