public static void Run(string[] args) { Console.WriteLine("Nusbio Initializing"); var serialNumber = Nusbio.Detect(); if (serialNumber == null) // Detect the first Nusbio available { Console.WriteLine("Nusbio not detected"); return; } var motionSensorGpio = 0; var red = NusbioGpio.Gpio1; var green = NusbioGpio.Gpio2; using (var nusbio = new Nusbio(serialNumber)) { var motionSensor = new DigitalMotionSensorPIR(nusbio, motionSensorGpio, 6); //var redLed = nusbio.GPIOS[red].AsLed; // Blink fast for 3 seconds when motion is detected //var greenLed = nusbio.GPIOS[green].AsLed; // Blink every 1/2 second just to tell system is running and is ok //greenLed.SetBlinkMode(500); Cls(nusbio); while (nusbio.Loop()) { var motionType = motionSensor.MotionDetected(); if (motionType == DigitalMotionSensorPIR.MotionDetectedType.MotionDetected) { ConsoleEx.Write(0, 8, string.Format("[{0}] MotionSensor:{1,-20}", DateTime.Now, motionType), ConsoleColor.DarkCyan); //redLed.SetBlinkMode(200); } else if (motionType == DigitalMotionSensorPIR.MotionDetectedType.None) { ConsoleEx.Write(0, 8, string.Format("[{0}] MotionSensor:{1,-20}", DateTime.Now, motionType), ConsoleColor.DarkCyan); //redLed.SetBlinkModeOff(); } if (Console.KeyAvailable) { var k = Console.ReadKey(true).Key; if (k == ConsoleKey.Q) { break; } if (k == ConsoleKey.C) { Cls(nusbio); } } } } Console.Clear(); }
static void CameraCaptureMode(Nusbio nusbio) { CameraCaptureModeCls(); var motionSensor = new DigitalMotionSensorPIR(nusbio, _motionSensor, 6); nusbio[_cameraGpio].High(); // Should be high by default if (ConsoleEx.Question(2, "Nusbio ready, turn camera on, Continue Y)es N)o", new List <char>() { 'Y', 'N' }) == 'Y') { CameraCaptureModeCls(); // it seems that the first pulse does not trigger a photo // and a second pulse is necessary Console.WriteLine("Initializing Camera..."); CameraCapture(nusbio, false); CameraCapture(nusbio, true); CameraCaptureModeCls(); while (nusbio.Loop(20)) { var k = SmartWait(.5); if (k.Key == ConsoleKey.Q) { break; } if (motionSensor.MotionDetected() == MotionDetectedType.MotionDetected) { Console.WriteLine("Motion detected at {0}", DateTime.Now); CameraCapture(nusbio); } } } }