Exemplo n.º 1
0
        public static void Main()
        {
            var ds1307 = new DS1307();

            //Comment the following line to not set the time to DS1307 board again
            ds1307.SetTime(
                Year: 2018,
                Month: 01,
                Day: 23,
                Hour: 16,
                Minute: 59,
                Second: 0
                );

            while (true)
            {
                var time          = ds1307.GetTime();
                var formattedDate = StringUtility.Format(
                    "Netduino Time in UTC: {0}",
                    time.ToString("yyyy-MM-ddTHH:mm:ssZ")
                    );

                Debug.Print(formattedDate);
                //sleep for 5 seconds
                Thread.Sleep(5000);
            }
        }
Exemplo n.º 2
0
        private void DS1307Test(II2cBus i2c)
        {
            Console.WriteLine("+DS1307 Test");

            var rtc = new DS1307(i2c);

            Console.Write(" Checking IsRunning...");
            var running = rtc.IsRunning;

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

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

            DateTime now = new DateTime();

            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));
            }
        }