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;
- using GHIElectronics.NETMF.System;
- namespace Gadgeteer_Clock_Game_01
- {
- public partial class Program
- {
- // recalculate everything each time the timer ticks
- GT.Timer timer = new GT.Timer(100, GT.Timer.BehaviorType.RunContinuously);
- // declare an array
- double[] xPosLed = new double[12];
- double[] yPosLed = new double[12];
- // keep with in a 96 radius circle with the centre at 0,0
- double xPosTarget;
- double yPosTarget;
- double xPosCurrent = 0;
- double yPosCurrent = 0;
- double[] clockDistance = new double[12];
- //double clockSize = 160;
- double clockSize = 128;
- int smoothValue = 4;
- // This method is run when the mainboard is powered up or reset.
- void ProgramStarted()
- {
- // create the clock face
- // a clock face with a radius of 160 units
- // this means that the biggest value is 255 and the smallest is 64
- //for (int increment = 1; increment <= 13; increment++)
- for (int increment = 0; increment <= 6; increment++)
- {
- xPosLed[increment] = MathEx.Cos((MathEx.PI / 6) * increment) * clockSize;
- yPosLed[increment] = MathEx.Sin((MathEx.PI / 6) * increment) * clockSize;
- Debug.Print("x " + increment + " " + xPosLed[increment]);
- Debug.Print("y " + increment + " " + yPosLed[increment]);
- }
- led.GreenBlueSwapped = true;
- led1.GreenBlueSwapped = true;
- led2.GreenBlueSwapped = true;
- led3.GreenBlueSwapped = true;
- led4.GreenBlueSwapped = true;
- led5.GreenBlueSwapped = true;
- //led6.GreenBlueSwapped = true;
- //led7.GreenBlueSwapped = true;
- //led8.GreenBlueSwapped = true;
- //led9.GreenBlueSwapped = true;
- //led10.GreenBlueSwapped = true;
- //led11.GreenBlueSwapped = true;
- // create a timer robot
- timer.Tick += new GT.Timer.TickEventHandler(timer_Tick);
- timer.Start();
- // tell everyone
- Debug.Print("Program Started");
- }
- void timer_Tick(GT.Timer timer)
- {
- // get joystick position
- xPosTarget = 128 - (joystick.GetJoystickPostion().X * 255); // assigns the x-direction from 0 to 1 to the variable holder xPosTarget
- yPosTarget = 128 - (joystick.GetJoystickPostion().Y * 255); // assigns the y-direction from 0 to 1 to the variable holder yPosTarget
- // update current position
- xPosCurrent += (xPosTarget - xPosCurrent) / smoothValue;
- yPosCurrent += (yPosTarget - yPosCurrent) / smoothValue;
- Debug.Print(xPosCurrent + " " + yPosCurrent);
- // work out clock distances from current position
- for (int increment02 = 0; increment02 <= 6; increment02++)
- {
- clockDistance[increment02] = MathEx.Sqrt(((xPosLed[increment02] - xPosCurrent) * (xPosLed[increment02] - xPosCurrent)) + ((yPosLed[increment02] - yPosCurrent) * (yPosLed[increment02] - yPosCurrent)));
- Debug.Print(increment02+" "+clockDistance[increment02]);
- switch (increment02)
- {
- case 0:
- led.SetBlueIntensity((int)(clockDistance[increment02]));
- led.SetRedIntensity(255-(int)(clockDistance[increment02]));
- break;
- case 1:
- led1.SetBlueIntensity((int)(clockDistance[increment02]));
- led1.SetRedIntensity(255-(int)(clockDistance[increment02]));
- break;
- case 2:
- led2.SetBlueIntensity((int)(clockDistance[increment02]));
- led2.SetRedIntensity(255-(int)(clockDistance[increment02]));
- break;
- case 3:
- led3.SetBlueIntensity((int)(clockDistance[increment02]));
- led3.SetRedIntensity(255-(int)(clockDistance[increment02]));
- break;
- case 4:
- led4.SetBlueIntensity((int)(clockDistance[increment02]));
- led4.SetRedIntensity(255-(int)(clockDistance[increment02]));
- break;
- case 5:
- led5.SetBlueIntensity((int)(clockDistance[increment02]));
- led5.SetRedIntensity(255-(int)(clockDistance[increment02]));
- break;
- case 6:
- //led6.SetBlueIntensity((int)(clockDistance[increment02]));
- break;
- case 7:
- //led7.SetBlueIntensity((int)(clockDistance[increment02]));
- break;
- case 8:
- //led8.SetBlueIntensity((int)(clockDistance[increment02]));
- break;
- case 9:
- //led9.SetBlueIntensity((int)(clockDistance[increment02]));
- break;
- case 10:
- //led10.SetBlueIntensity((int)(clockDistance[increment02]));
- break;
- case 11:
- //led11.SetBlueIntensity((int)(clockDistance[increment02]));
- break;
- default:
- break;
- }
- }
- // random target angle and distance?
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment