/** * Binds the analog axis with the specified analog axis ID (such as "joystick 1 * axis0") and description (such as "Left Mouse Button") to a game action with * the specified game action ID (such as "interact") and description (e.g. * "Interact with Buttons"). * * The analog axis will be act as a button and activate when it has a value * greater than triggerPoint (if triggerPoint > 0) or a value less than * triggerPoint (if triggerPoint < 0). * * Returns true if this was the first input to be bound to the specified * gameAction. */ public static bool BindAnalogButton(string gameActionID, string gameActionDescr, string analogAxisID, string buttonDescr, float triggerPoint) { AnalogButton analogButton = new AnalogButton(analogAxisID, buttonDescr, triggerPoint); analogButtons.Add(analogButton); return(BindButton(gameActionID, gameActionDescr, analogButton)); }
public byte GetAnalogButton(AnalogButton a) { if (readBuffer == null) { return(0); } return((byte)(readBuffer[(uint)a])); }
public static void Run(string[] args) { Console.WriteLine("Nusbio initialization"); var serialNumber = Nusbio.Detect(); if (serialNumber == null) // Detect the first Nusbio available { Console.WriteLine("Nusbio not detected"); return; } var lightSensorAnalogPort = 2; var motionSensorAnalogPort = 0; var buttonSensorAnalogPort = 1; var ledGpio = NusbioGpio.Gpio5; using (var nusbio = new Nusbio(serialNumber)) { Cls(nusbio); var halfSeconds = new TimeOut(333); // Mcp300X Analog To Digital - SPI Config ad = new MCP3008(nusbio, selectGpio: NusbioGpio.Gpio3, mosiGpio: NusbioGpio.Gpio1, misoGpio: NusbioGpio.Gpio2, clockGpio: NusbioGpio.Gpio0); ad.Begin(); var analogMotionSensor = new AnalogMotionSensor(nusbio, 4); analogMotionSensor.Begin(); var button = new AnalogButton(nusbio); var lightSensor = CalibrateLightSensor(new AnalogLightSensor(nusbio), AnalogLightSensor.LightSensorType.CdsPhotoCell_3mm_45k_140k); lightSensor.Begin(); // Analog Port 5, 6, 7 are only available in // Analog Extension PCBv2 const int multiButtonPort = 5; AnalogSensor multiButton = null; //multiButton = new AnalogSensor(nusbio, multiButtonPort); //multiButton.Begin(); // TC77 Temperature Sensor SPI var tc77 = new TC77(nusbio, clockGpio: NusbioGpio.Gpio0, mosiGpio: NusbioGpio.Gpio1, misoGpio: NusbioGpio.Gpio2, selectGpio: NusbioGpio.Gpio4 ); tc77.Begin(); if (nusbio.Type == NusbioType.NusbioType1_Light) { tc77._spi.SoftwareBitBangingMode = true; ad._spiEngine.SoftwareBitBangingMode = true; } while (nusbio.Loop()) { if (halfSeconds.IsTimeOut()) { nusbio[ledGpio].AsLed.ReverseSet(); ConsoleEx.WriteLine(0, 2, string.Format("{0,-15}", DateTime.Now), ConsoleColor.Cyan); lightSensor.SetAnalogValue(ad.Read(lightSensorAnalogPort)); ConsoleEx.WriteLine(0, 4, string.Format("Light Sensor : {0,-18} (ADValue:{1:000.000}, Volt:{2:0.00}) ", lightSensor.CalibratedValue.PadRight(18), lightSensor.AnalogValue, lightSensor.Voltage), ConsoleColor.Cyan); analogMotionSensor.SetAnalogValue(ad.Read(motionSensorAnalogPort)); var motionType = analogMotionSensor.MotionDetected(); if (motionType == DigitalMotionSensorPIR.MotionDetectedType.MotionDetected || motionType == DigitalMotionSensorPIR.MotionDetectedType.None) { ConsoleEx.Write(0, 6, string.Format("Motion Sensor : {0,-18} (ADValue:{1:000.000}, Volt:{2:0.00}) ", motionType, analogMotionSensor.AnalogValue, analogMotionSensor.Voltage), ConsoleColor.Cyan); } ConsoleEx.WriteLine(0, 8, string.Format("Temperature Sensor : {0:0.00}C {1:0.00}F ", tc77.GetTemperature(), tc77.GetTemperature(AnalogTemperatureSensor.TemperatureType.Fahrenheit)), ConsoleColor.Cyan); button.SetAnalogValue(ad.Read(buttonSensorAnalogPort)); ConsoleEx.WriteLine(0, 10, string.Format("Button : {0,-18} [{1:0000}, {2:0.00}V] ", button.Down ? "Down" : "Up", button.AnalogValue, button.Voltage), ConsoleColor.Cyan); if (multiButton != null) { multiButton.SetAnalogValue(ad.Read(multiButtonPort)); ConsoleEx.Write(0, 12, string.Format("Multi Button : {0,-18} (ADValue:{1:000.000}, Volt:{2:000.000})", multiButton.AnalogValue > 2 ? "Down" : "Up ", multiButton.AnalogValue, multiButton.Voltage), ConsoleColor.Cyan); } } if (Console.KeyAvailable) { var k = Console.ReadKey(true).Key; if (k == ConsoleKey.C) { Cls(nusbio); } if (k == ConsoleKey.Q) { break; } Cls(nusbio); } } } Console.Clear(); }
public byte GetAnalogButton(AnalogButton a) { if (readBuffer == null) return 0; return (byte)(readBuffer[(uint)a]); }