Esempio n. 1
0
        void StartCountdown()
        {
            currentDate = rtc.GetTime();

            display.WriteLine("Current Date:", 0);
            display.WriteLine($"{currentDate.Month}/{currentDate.Day}/{currentDate.Year}", 1);
            display.WriteLine("Christmas Countdown:", 2);

            while (true)
            {
                UpdateCountdown();
                Thread.Sleep(60000);
            }
        }
Esempio n. 2
0
        public void SetClockFromRtc()
        {
            DateTime time = clock.GetTime();

            setTime.Invoke(time);
#if DEBUG
            Console.WriteLine("Time set from RTC: " + time.ToString(new CultureInfo("pl-PL")));
#endif
        }
Esempio n. 3
0
        protected void DS1307Test()
        {
            Console.WriteLine("DS1307Test...");

            var now     = new DateTime();
            var running = rtc.IsRunning;

            Console.WriteLine($"{(running ? "is running" : "is not running")}");

            if (!running)
            {
                Console.WriteLine(" Starting RTC...");
                rtc.IsRunning = true;
            }

            while (true)
            {
                for (int i = 0; i < 3; i++)
                {
                    now = rtc.GetTime();
                    Console.WriteLine($" RTC current time is: {now.ToString("MM/dd/yy HH:mm:ss")}");
                    Thread.Sleep(1000);
                }

                var rand = new Random();

                if (now.Year < 2019)
                {
                    now = DateTime.Now;
                }
                else
                {
                    now = now.AddSeconds(rand.Next(1, 30));
                }

                Console.WriteLine($" Setting RTC to : {now.ToString("MM/dd/yy HH:mm:ss")}");

                var data = new byte[56];

                for (int i = 0; i < 56; i++)
                {
                    data[i] = (byte)rand.Next(256);
                }

                Console.WriteLine($" Writing to RTC RAM   : {BitConverter.ToString(data)}");
                rtc.WriteRAM(0, data);
                Console.Write($" Reading from RTC RAM : ");
                data = rtc.ReadRAM(0, 56);
                Console.WriteLine(BitConverter.ToString(data));

                Thread.Sleep(rand.Next(1, 5));
            }
        }