Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- 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_Navigator_01
- {
- public partial class Program
- {
- // Variable holders that are available everywhere
- int blinkTick = (1000);
- //int ledBlinkLength = (250); // create a timebased variable holder for the length of the blinks
- int ledBlinkOffset = (5);
- //int ledBlinkSpace = (250);
- //int led1BlinkLength = (250); // create a timebased variable holder for the length of the blinks
- int led1BlinkOffset = (5);
- //int led1BlinkSpace = (250);
- Boolean[] ledBlinkCondition = new Boolean[11];
- Boolean[] led1BlinkCondition = new Boolean[11];
- // 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();
- *******************************************************************************************/
- // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
- Debug.Print("Program Started");
- GT.Timer timer = new GT.Timer(blinkTick); // create a tick event every tenth of a second
- timer.Tick += new GT.Timer.TickEventHandler(timer_Tick); // create an event handling robot to watch for the tick
- timer.Start(); // start the timer
- joystick.DebugPrintEnabled = true; // allow the program to ask the joystick questions
- }
- void timer_Tick(GT.Timer timer)
- {
- // this is what the event handling robot will do when it sees an event
- //look at the joystick
- double joystickPosX = joystick.GetJoystickPostion().X; // assigns the x-direction from 0 to 1 to the variable holder joystickPosX
- double joystickPosY = joystick.GetJoystickPostion().Y; // assigns the y-direction from 0 to 1 to the variable holder joystickPosY
- //Debug.Print(((int)(joystickPosX * 1000)).ToString()); // prints the current joystick position * 255 in the x-direction
- //Debug.Print(((int)(joystickPosY * 1000)).ToString()); // prints the current joystick position * 255 in the y-direction
- for (int increment03 = 0; increment03 < 10; increment03++)
- {
- ledBlinkCondition[increment03] = false;
- led1BlinkCondition[increment03] = false;
- }
- ledBlinkOffset = ((int)(joystickPosX * 10))-1;
- led1BlinkOffset = 9 - ledBlinkOffset;
- Debug.Print("0 " + ledBlinkOffset.ToString());
- Debug.Print("1 " + led1BlinkOffset.ToString());
- ledBlinkCondition[ledBlinkOffset] = true;
- led1BlinkCondition[led1BlinkOffset] = true;
- for (int increment02 = 0; increment02 < 10; increment02++)
- {
- // create a blink offset
- if (ledBlinkCondition[increment02])
- {
- led.SetRedIntensity(255);
- }
- else
- {
- led.SetRedIntensity(0);
- }
- if (led1BlinkCondition[increment02])
- {
- led1.SetRedIntensity(255);
- }
- else
- {
- led1.SetRedIntensity(0);
- }
- Thread.Sleep(100);
- }
- //ledBlinkOffset = ((int)(joystickPosX * 8)); // sets the led brightness to the current joystick position * 255 in the x-direction
- //led1BlinkOffset = 800 - ledBlinkOffset; // sets the led brightness to the current joystick position * 255 in the y-direction
- //Debug.Print(ledBlinkOffset.ToString());
- //Debug.Print(led1BlinkOffset.ToString());
- //ledBlinkLength = ((int)(joystickPosY * 1)); // sets the led brightness to the current joystick position * 255 in the x-direction
- //led1BlinkLength = ledBlinkLength; // sets the led brightness to the current joystick position * 255 in the x-direction
- //ledBlinkSpace = (blinkTick - ledBlinkOffset - (ledBlinkLength * 2));
- //led1BlinkSpace = (blinkTick - led1BlinkOffset - (led1BlinkLength * 2));
- //led1Blink();
- //ledBlink();
- }
- /*void ledBlink ()
- {
- Thread.Sleep(ledBlinkOffset);
- led.SetRedIntensity(255);
- Thread.Sleep(ledBlinkLength);
- led.SetRedIntensity(0);
- Thread.Sleep(ledBlinkSpace);
- led.SetRedIntensity(255);
- Thread.Sleep(ledBlinkLength);
- led.SetRedIntensity(0);
- }
- void led1Blink()
- {
- Thread.Sleep(led1BlinkOffset);
- led1.SetRedIntensity(255);
- Thread.Sleep(led1BlinkLength);
- led1.SetRedIntensity(0);
- Thread.Sleep(led1BlinkSpace);
- led1.SetRedIntensity(255);
- Thread.Sleep(led1BlinkLength);
- led1.SetRedIntensity(0);
- }*/
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment