public static void Main()
        {
            using (var lcd = new KanaLCD(0x38, 2, 40))
            {
                lcd.Initialize();
                lcd.BackLight = true;
                lcd.Write("Initializing...");
            }

            using (var clock = new RX8025NB())
            {
                clock.Initialize();
                clock.CurrentTime = GetTimeViaHttp(9);
                clock.Interrupt   = RX8025NB.InterruptMode.Pulse1Hz;
            }

            using (var thermometer = new ADT7410(ADT7410.MeasurementMode.OneSamplePerSecond))
            {
                thermometer.Initialize();
            }

            var interruptPort = new InterruptPort(Pins.GPIO_PIN_D12, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeLow);
            var lightPort     = new SecretLabs.NETMF.Hardware.AnalogInput(Pins.GPIO_PIN_A0);

            // RTCモジュールによる割り込み処理
            interruptPort.OnInterrupt += (_, __, ___) =>
            {
                // 割り込みから秒カウンタの書き換えまで92μsかかる
                Thread.Sleep(1);

                DateTime currentTime;
                using (var clock = new RX8025NB())
                {
                    currentTime = clock.CurrentTime;
                }

                StartCounters();

                if (anotherDisplayCount <= 0)
                {
                    ShowMainDisplay(currentTime);
                }
                else
                {
                    ShowAnotherDisplay(currentTime);
                }

                ManageBackLight(lightPort);
            };

            while (true)
            {
                // メインスレッドは特になにもしない
                Thread.Sleep(1000);
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            var port  = "COM7";
            var temp1 = new ADT7410(port, 0x48);
            var lcd1  = new AQM1602(port, 0x3e);

            lcd1.LcdInit();

            while (true)
            {
                lcd1.LcdClear();
                var msg1 = DateTime.Now.ToString("HH:mm:ss");
                lcd1.MessageWrite(Encoding.ASCII.GetBytes(msg1));

                lcd1.LcdNewLine();
                var t    = temp1.TempRead();
                var msg2 = t.ToString("F1");
                lcd1.MessageWrite(Encoding.ASCII.GetBytes(msg2));

                Task.Delay(3000).Wait();
            }
        }
        private static void ShowAnotherDisplay(DateTime currentTime)
        {
            double temperature;

            using (var thermometer = new ADT7410(ADT7410.MeasurementMode.OneSamplePerSecond))
            {
                temperature = thermometer.ReadTemperature();
            }

            using (var lcd = new KanaLCD(0x38, 2, 40))
            {
                lcd.ClearScreen();
                lcd.SetCursor(0, 0);
                lcd.Write(currentTime.Year.To4DigitString() + "/"
                          + currentTime.Month.To2DigitString() + "/" + currentTime.Day.To2DigitString());
                lcd.SetCursor(1, 0);
                lcd.Write(currentTime.Hour.To2DigitString() + ":" + currentTime.Minute.To2DigitString() + ":"
                          + currentTime.Second.To2DigitString() + " "
                          + ((int)temperature).To2DigitString() + "." + (int)(temperature * 10) % 10 + "°C");
            }

            anotherDisplayCount--;
        }