public static void Main()
        {
            var rtc = new DS3231(0x68, 100, Pins.GPIO_PIN_D8);

            //
            //  Set the current time.
            //
            rtc.CurrentDateTime = new DateTime(2017, 11, 11, 14, 16, 0);
            Debug.Print("Current time: " + rtc.CurrentDateTime.ToString("dd MMM yyyy HH:mm:ss"));
            Debug.Print("Temperature: " + rtc.Temperature.ToString("f2"));
            rtc.ClearInterrupt(DS323x.Alarm.BothAlarmsRaised);
            rtc.DisplayRegisters();
            rtc.SetAlarm(DS323x.Alarm.Alarm1Raised, new DateTime(2017, 10, 29, 9, 43, 15),
                         DS323x.AlarmType.WhenSecondsMatch);
            rtc.OnAlarm1Raised += rtc_OnAlarm1Raised;
            rtc.DisplayRegisters();
            Thread.Sleep(Timeout.Infinite);
        }
Exemple #2
0
        protected void InitializePeripherals()
        {
            _rtc = new DS3231(0x68, 100);
            // Run once to adjust the time on the RTC
            // _rtc.CurrentDateTime = new DateTime(2018, 12, 17, 22, 41, 0);

            _lcd = new Lcd2004
                   (
                RS: N.Pins.GPIO_PIN_D8,
                E: N.Pins.GPIO_PIN_D9,
                D4: N.Pins.GPIO_PIN_D10,
                D5: N.Pins.GPIO_PIN_D11,
                D6: N.Pins.GPIO_PIN_D12,
                D7: N.Pins.GPIO_PIN_D13
                   );

            H.PWM _contrast = new H.PWM(H.Cpu.PWMChannel.PWM_0, 1000, 0.6, false);
            _contrast.Start();
        }
Exemple #3
0
        public static void Main()
        {
            // Set I2C pins for ESP32 (choose your own)
            Configuration.SetPinFunction(21, DeviceFunction.I2C1_DATA);
            Configuration.SetPinFunction(22, DeviceFunction.I2C1_CLOCK);

            // Setup I2C
            var settings  = new I2cConnectionSettings(1, DS3231.DefaultI2cAddress, I2cBusSpeed.StandardMode);
            var i2cDevice = I2cDevice.Create(settings);


            using (var rtc = new DS3231(i2cDevice))
            {
                // Set DS3231 time
                rtc.DateTime = new DateTime(2021, 2, 27, 16, 01, 0);

                // Read time
                DateTime dt = rtc.DateTime;

                // Read temperature
                double temp = rtc.ReadTemperature();

                // Set alarm
                var alarmOne = new DS3231AlarmOne(0, new TimeSpan(0, 0, 59), DS3231AlarmOneMatchMode.Seconds);
                rtc.SetAlarmOne(alarmOne);
                rtc.EnabledAlarm = DS3231Alarm.AlarmOne;
                while (true)
                {
                    dt = rtc.DateTime;
                    Debug.WriteLine(dt.ToString());
                    if (rtc.CheckIfAlarmTriggered(DS3231Alarm.AlarmOne))
                    {
                        Debug.WriteLine("Alarm triggerred");
                        rtc.ResetAlarmTriggeredStates();
                    }
                    Thread.Sleep(1000);
                }
            }
        }
        protected void InitializePeripherals()
        {
            _rtc = new DS3231(0x68, 100);

            _rgbPwmLed = new RgbPwmLed
                         (
                N.PWMChannels.PWM_PIN_D6,
                N.PWMChannels.PWM_PIN_D5,
                N.PWMChannels.PWM_PIN_D3,
                1.05f,
                1.5f,
                1.5f,
                false
                         );

            _humiditySensor = new HumiditySensorController
                              (
                N.Pins.GPIO_PIN_A0,
                N.Pins.GPIO_PIN_D7
                              );

            _rgbPwmLed.SetColor(Netduino.Foundation.Color.Red);
        }
        public static void Main()
        {
            //Input Sensors
            Microsoft.SPOT.Hardware.AnalogInput WaterLevel      = new Microsoft.SPOT.Hardware.AnalogInput(Cpu.AnalogChannel.ANALOG_0);
            Microsoft.SPOT.Hardware.AnalogInput LDR             = new Microsoft.SPOT.Hardware.AnalogInput(Cpu.AnalogChannel.ANALOG_1);
            Microsoft.SPOT.Hardware.AnalogInput MotionDetection = new Microsoft.SPOT.Hardware.AnalogInput(Cpu.AnalogChannel.ANALOG_2);

            //Output Ports for Relays
            relay01 = new OutputPort(Pins.GPIO_PIN_D5, true);
            relay02 = new OutputPort(Pins.GPIO_PIN_D6, true);
            relay03 = new OutputPort(Pins.GPIO_PIN_D7, true);
            relay04 = new OutputPort(Pins.GPIO_PIN_D8, true);
            relay05 = new OutputPort(Pins.GPIO_PIN_D9, true);
            relay06 = new OutputPort(Pins.GPIO_PIN_D10, true);
            relay07 = new OutputPort(Pins.GPIO_PIN_D11, true);
            relay08 = new OutputPort(Pins.GPIO_PIN_D12, true);

            //DS3231 definition
            DS3231 rtc = new DS3231(0x68, 100, Pins.GPIO_PIN_D3);

            while (true)
            {
                //Getting current time from DS3231
                int year      = (int)rtc.CurrentDateTime.Year;
                int month     = (int)rtc.CurrentDateTime.Month;
                int day       = (int)rtc.CurrentDateTime.Day;
                int hour      = (int)rtc.CurrentDateTime.Hour;
                int minute    = (int)rtc.CurrentDateTime.Minute;
                int second    = (int)rtc.CurrentDateTime.Second;
                int dayOfWeek = (int)rtc.CurrentDateTime.DayOfWeek;

                //If year is wrong
                if (year < 2000)
                {
                    year += 100;
                }

                //Looking sensor values to decide relay states
                sensorTest(WaterLevel, LDR, MotionDetection);


                //Relay states are going to be decided by Time Program
                if (timeMode == true)
                {
                    //SD Card Read Mode On
                    if (SDCardRead(1) != "")
                    {
                        //Reading every relays' programs and activate them
                        for (int i = 1; i <= 8; i++)
                        {
                            string[] relayAll = StringSplitter(SDCardRead(i));
                            TimeToAct(i, hour, minute, DayOfWeekToString(dayOfWeek), int.Parse(relayAll[1]),
                                      int.Parse(relayAll[2]), int.Parse(relayAll[3]), int.Parse(relayAll[4]),
                                      DetectDay(int.Parse(relayAll[5])));
                        }

                        //Write it from VS
                    }
                    else
                    {
                        // Relay no:1 14:10 - 14:59 Only Monday
                        TimeToAct(1, hour, minute, DayOfWeekToString(dayOfWeek), 14, 10, 14, 59, DetectDay(2));
                        SDCardWrite(1, 14, 10, 14, 59, 2); //It is a writing example

                        // Relay no:2 12:10 - 16:27 Only Tuesday
                        TimeToAct(2, hour, minute, DayOfWeekToString(dayOfWeek), 12, 10, 16, 27, DetectDay(3));

                        // Relay no:3 13:06 - 13:09 Only Thursday
                        TimeToAct(3, hour, minute, DayOfWeekToString(dayOfWeek), 13, 06, 13, 18, DetectDay(7));

                        // Relay no:4 09:25 - 18:17 Only Friday
                        TimeToAct(4, hour, minute, DayOfWeekToString(dayOfWeek), 09, 25, 18, 17, DetectDay(11));

                        // Relay no:5 10:00 - 12:00 Everyday
                        TimeToAct(5, hour, minute, DayOfWeekToString(dayOfWeek), 10, 00, 12, 00, DetectDay(510510));

                        // Relay no:6 04:35 - 14:40 Weekend (Saturday & Sunday)
                        TimeToAct(6, hour, minute, DayOfWeekToString(dayOfWeek), 04, 35, 14, 40, DetectDay(221));

                        // Relay no:7 12:15 - 12:46 Weekdays (Monday & Tuesday & Wednesday & Thursday & Friday)
                        TimeToAct(7, hour, minute, DayOfWeekToString(dayOfWeek), 12, 15, 12, 46, DetectDay(2310));

                        // Relay no:8 02:00 - 02:02 Monday & Wednesday & Friday & Sunday
                        TimeToAct(8, hour, minute, DayOfWeekToString(dayOfWeek), 02, 00, 02, 02, DetectDay(1870));
                    }
                }

                //Printing Current Time
                Debug.Print("Current Date: " + day + "/" + month + "/" + year);
                Debug.Print("Current Hour: " + hour + ":" + minute + "." + second);
                Debug.Print("Current Day of Week: " + DayOfWeekToString(dayOfWeek));

                //Printing Sensor Values
                Debug.Print("Water Level Sensor: " + (int)(WaterLevel.Read() * 100));
                Debug.Print("LDR Level Sensor: " + (int)(LDR.Read() * 100));
                Debug.Print("Motion Detection Sensor: " + (int)(MotionDetection.Read() * 100));


                Thread.Sleep(1000);
            }
            Thread.Sleep(Timeout.Infinite);
        }