La première application
Retour à la page La Machine
using System.Threading;
using Fez;
using GHIElectronics.NETMF.USBHost;
using Microsoft.SPOT;
namespace FirstApp
{
public class Program
{
static USBH_Joystick j;
public static void Main()
{
FEZ_Shields.DCMotorDriver2A.Initialize();
// Instant stop
FEZ_Shields.DCMotorDriver2A.Move(0, 0);
// Subscribe to USBH event.
USBHostController.DeviceConnectedEvent += DeviceConnectedEvent;
// Sleep forever
Thread.Sleep(Timeout.Infinite);
}
static void DeviceConnectedEvent(USBH_Device device)
{
if (device.TYPE == USBH_DeviceType.Joystick)
{
Debug.Print("Joystick Connected");
j = new USBH_Joystick(device);
j.JoystickXYMove += JoystickXYMove;
j.JoystickXY2Move += JoystickXYMove;
}
}
static void JoystickXYMove(USBH_Joystick sender,
USBH_JoystickEventArgs args)
{
sbyte leftMotor = sbyte.Parse((System.Math.Ceiling((double)sender.Cursor.Y / 512 * -100)).ToString());
sbyte rightMotor = sbyte.Parse((System.Math.Ceiling((double)sender.Cursor2.Y / 512 * -100)).ToString());
if (leftMotor>=-15 && leftMotor<=15)
leftMotor = 0;
if (rightMotor >= -15 && rightMotor <= 15)
rightMotor = 0;
FEZ_Shields.DCMotorDriver2A.Move(rightMotor, leftMotor);
}
}
}