private async void InitDrivers() { await Ds3231.Initialize( ); await Tsl2561.Initialize( ); await Buzzer.Initialize(17); await Ssd1308.Initialize( ); // Get DateTime in Ds3231, auto net sync DateTime LocalDateTime = Ds3231.Now; double Temperature = Ds3231.Temperature; // Get luminosity double Luminosity = Tsl2561.Lux; // Buzzz Buzzer.Tone(1400, 800, 200); // Draw Frame Ssd1308.DrawHLine(0, 0, 128); Ssd1308.DrawVLine(0, 0, 64); Ssd1308.DrawVLine(127, 0, 64); Ssd1308.DrawHLine(0, 63, 128); Ssd1308.DrawChar('M', DisplayFonts.System7pt, 87, 3); Ssd1308.DrawChar('A', DisplayFonts.System7pt, 97, 3); Ssd1308.DrawChar('N', DisplayFonts.System7pt, 107, 3); Ssd1308.DrawChar('U', DisplayFonts.System7pt, 117, 3); }
static void Main(string[] args) { // This project contains DS1307, DS3231, PCF8563 I2cConnectionSettings settings = new I2cConnectionSettings(1, Ds3231.DefaultI2cAddress); I2cDevice device = I2cDevice.Create(settings); using (Ds3231 rtc = new Ds3231(device)) { // set time rtc.DateTime = DateTime.Now; // loop while (true) { // read time DateTime dt = rtc.DateTime; Console.WriteLine($"Time: {dt.ToString("yyyy/MM/dd HH:mm:ss")}"); Console.WriteLine($"Temperature: {rtc.Temperature.Celsius} ℃"); Console.WriteLine(); // wait for a second Thread.Sleep(1000); } } }
void Initialize() { Console.WriteLine("Initialize hardware..."); sensor = new Ds3231(Device, Device.CreateI2cBus(), Device.Pins.D06); sensor.OnAlarm1Raised += Sensor_OnAlarm1Raised; }
static void Main(string[] args) { I2cConnectionSettings settings = new I2cConnectionSettings(1, Ds3231.DefaultI2cAddress); // get I2cDevice (in Linux) UnixI2cDevice device = new UnixI2cDevice(settings); // get I2cDevice (in Win10) //Windows10I2cDevice device = new Windows10I2cDevice(settings); using (Ds3231 rtc = new Ds3231(device)) { // set DS3231 time rtc.DateTime = DateTime.Now; // loop while (true) { // read temperature double temp = rtc.Temperature; // read time DateTime dt = rtc.DateTime; Console.WriteLine($"Time: {dt.ToString("yyyy/MM/dd HH:mm:ss")}"); Console.WriteLine($"Temperature: {temp} ℃"); Console.WriteLine(); // wait for a second Thread.Sleep(1000); } } }
/// <summary> /// Ds3231 RTC /// </summary> public RTC() { _settings = new I2cConnectionSettings(1, Ds3231.DefaultI2cAddress); using (I2cDevice device = I2cDevice.Create(_settings)) { _rtc = new Ds3231(device); } }
/// <summary> /// Ds3231 RTC /// </summary> /// <param name="settings">Define customized settings or set null to allow default</param> public RTC(I2cConnectionSettings settings) { if (settings == null) { settings = new I2cConnectionSettings(1, Ds3231.DefaultI2cAddress); } _settings = settings; using (I2cDevice device = I2cDevice.Create(_settings)) { _rtc = new Ds3231(device); } }
/// <summary> /// Opens the clock and begins invoking the <see cref="Ticked"/> event every second. /// </summary> /// <exception cref="InvalidOperationException"> /// Thrown if the clock is already open. /// </exception> public void Open() { if (IsOpen) { throw new InvalidOperationException("The clock is already open"); } IsOpen = true; ds3231 = new Ds3231(I2cDevice.Create( new I2cConnectionSettings(1, Ds3231.DefaultI2cAddress))) { IntSqwPinMode = Ds3231IntSqwPinMode.SquareWave, SquareWaveRate = Ds3231SquareWaveRate.Rate1Hz }; gpio.OpenPin(intSqwPin); gpio.SetPinMode(intSqwPin, PinMode.Input); gpio.RegisterCallbackForPinValueChangedEvent(intSqwPin, PinEventTypes.Falling, OnSqwInterrupt); }
void Initialize() { Console.WriteLine("Initialize hardware..."); sensor = new Ds3231(Device, Device.CreateI2cBus(), null); }