static void Main() { //Compile with: // dotnet publish ./RaspbianNetCoreDemo -c Release -r linux-arm --self-contained var taskSchedulerUtility = new TaskSchedulerUtility(); var fileUtils = new AsyncFileUtil(); var pinController = new LinuxPinController(fileUtils, taskSchedulerUtility); var ledPin = pinController.GetOrCreateOutputPin(LedPinNumber); BlockingTimer sleepTimer = new BlockingTimer(TimeSpan.FromMilliseconds(100)); LedControl ledControl = new LedControl(ledPin, sleepTimer); //while (true) //{ // ledControl.Blink(); //} var lightSensorDevice = new I2cDevice(I2cDevicePath, LightSensorDeviceAddress); var lightSensor = new APDS9301_LightSensor(lightSensorDevice, APDS9301_LightSensor.MinimumPollingPeriod); while (true) { float currentLuminosity = lightSensor.Luminosity; if (!ledControl.State && currentLuminosity <= OnMinimumLuminosity) { ledControl.Blink(); ledControl.Blink(); ledControl.TurnOnLed(); System.Diagnostics.Debug.WriteLine(currentLuminosity.ToString()); } else if (ledControl.State && currentLuminosity > OnMinimumLuminosity) { ledControl.TurnOffLed(); System.Diagnostics.Debug.WriteLine(currentLuminosity.ToString()); } Thread.Sleep(10); } //TODO: Dispose these somehow // Only care if exception is thrown on startup when the I2C Bus and IO Pins are already setup I guess //lightSensor.Dispose(); //pinController.Dispose(); }
private void Tick(ThreadPoolTimer timer) { float currentLuminosity = _lightSensor.Luminosity; if (!_ledController.State && currentLuminosity <= OnMinimumLuminosity) { _ledController.Blink(); _ledController.Blink(); _ledController.TurnOnLed(); System.Diagnostics.Debug.WriteLine(currentLuminosity.ToString()); } else if (_ledController.State && currentLuminosity > OnMinimumLuminosity) { _ledController.TurnOffLed(); System.Diagnostics.Debug.WriteLine(currentLuminosity.ToString()); } }
static void Main() { GpioPin led = GpioController.GetDefault().OpenPin(FezPins.GpioPin.D0); led.SetDriveMode(GpioPinDriveMode.Output); BlockingTimer sleepTimer = new BlockingTimer(TimeSpan.FromMilliseconds(100)); LedControl ledControl = new LedControl(led, sleepTimer); int sdaPin = FezPins.GpioPin.A0; int slcPin = FezPins.GpioPin.A1; int lightSensorDeviceAddress = 0x39; I2cConnectionSettings ledDeviceConnectionSettings = new I2cConnectionSettings(lightSensorDeviceAddress, I2cAddressFormat.SevenBit, I2cBusSpeed.StandardMode); I2cControllerSoftwareProvider i2cProvider = new I2cControllerSoftwareProvider(sdaPin, slcPin, false); I2cController i2cController = I2cController.FromProvider(i2cProvider); I2cDevice lightSensorDevice = i2cController.GetDevice(ledDeviceConnectionSettings); var lightSensor = new APDS9301_LightSensor(lightSensorDevice, APDS9301_LightSensor.MinimumPollingPeriod); while (true) { float currentLuminosity = lightSensor.Luminosity; if (!ledControl.State && currentLuminosity <= OnMinimumLuminosity) { ledControl.Blink(); ledControl.Blink(); ledControl.TurnOnLed(); System.Diagnostics.Debug.WriteLine(currentLuminosity.ToString()); } else if (ledControl.State && currentLuminosity > OnMinimumLuminosity) { ledControl.TurnOffLed(); System.Diagnostics.Debug.WriteLine(currentLuminosity.ToString()); } Thread.Sleep(10); } }
public void Run() { while (true) { float currentLuminosity = _lightSensor.Luminosity; if (!_ledControl.State && currentLuminosity <= OnMinimumLuminosity) { _ledControl.Blink(); _ledControl.Blink(); _ledControl.TurnOnLed(); System.Diagnostics.Debug.WriteLine(currentLuminosity.ToString()); } else if (_ledControl.State && currentLuminosity > OnMinimumLuminosity) { _ledControl.TurnOffLed(); System.Diagnostics.Debug.WriteLine(currentLuminosity.ToString()); } Thread.Sleep(10); } }