Arduino Uno: Missing Libraries

Advert

Arduino Uno: Missing Libraries

Home Forums Electronics in the Workshop Arduino Uno: Missing Libraries

Viewing 4 posts - 26 through 29 (of 29 total)
  • Author
    Posts
  • #775873
    Charles Lamont
    Participant
      @charleslamont71117
      On James Alford Said:

      I have another update on my experience with Copilot and ChatGPT; along with a couple of follow-up questions.

      I have finally succeeded in recreating code for the clock that I should to build, one day. I used ChatGPT initially as it seemed to be working well. However, when I studied the code that it had created, it was full of pin conflicts and other problems. No matter how I rephrased my requirements, I could not prevent the conflicts. I then tried Copilot which, after a number of false starts and several hours work, produced working code. You need to be extremely clear with your instructions, yet not too rigorous; an odd requirement. When I was very prescriptive the code would not even compile. Allowing the software more flexibility gave better results.

      However, I have a couple of questions.

      Question 1

      The set up uses a separate RTC to keep time and a LCD to display the time and day. I have buttons to advance and retard the time. Using these I can alter the time displayed on the LCD. I cannot work out, though, whether I need a specific “set” button for the time. Some clocks have them, whereas others do not.

      Is a set button needed?

      Question 2

      The code also sends signals to various pins to flash LEDs via a transistor circuit. There are pins to flash LEDs: once a second, once a minute, once an hour and once a day. It flashes another LED once, twice, thrice or four times on the quarters; and another on the hour, once, twice, thrice or more depending upon the hour.

      However, the code runs sequentially meaning the seconds LED stops flashing whilst the minute LED flashes; they both stop whilst the hour LED flashes and so on including when the quarters strike and the hours chime.

      Is there a way to modify the code so that these events so that they do not interrupt each other? In time, the LEDs will be replaced with relays to drive a visual display. The pauses will affect the accuracy of the mechanics.

      I can post examples of the code if it helps.

      James.

      Q1:

      With four buttons you can have a menu structure that allows almost anything. Planning and programming the decision tree is quite complicated though.

      Q2:

      Yes. Have a single loop that cycles every second and controls all the LEDs. Within that loop have series of conditional statements that decide which LEDs to light and which ones to switch off. For example, the seconds LED might switch on if the number of seconds is even. You might have a series of counters that increment every loop, the minute counter would cause the minute LED to come on when it reaches 60, at which point it would be reset. (These are off the top of my head as I don’t have much time right now)

      Advert
      #775968
      SillyOldDuffer
      Moderator
        @sillyoldduffer

        Here’s an example, Charles and I are thinking along the same lines.   The code flashes an LED once per second, and marks minutes by turning another LED on and off in a one minute cycle.   The code needed to add hour flashing and quarters is similar.  Works by detecting when seconds, minutes etc change.

        The LEDs are switched almost independently, out of sync only by the length of time needed to execute the if statements and read/write the pins; a few tens of microseconds.

        My implementation could be slicker.  Also, for simplicity I toggle the LEDs, when James might want them to pulse briefly when change is detected.  The logic for that is more complicated.

        Also, I faked a hhmmss clock rather than install an RTC module.

        alford1

        Seems to work on a breadboard.  Shout if doesn’t or the logic needs more work.

        Dave

        #775990
        SillyOldDuffer
        Moderator
          @sillyoldduffer

          Did I say it was working!   The LEDs flash correctly, but fakeClock() is up to 01:98:54   A bug in the minutes calculation, and it takes an hour to appear.  I think I see it, others might enjoy finding my blunder for themselves!

          🙁

          Dave

          #776017
          James Alford
          Participant
            @jamesalford67616

            Thank you, Dave and Charles. I shall have a proper read of your suggestions later.

            Dave: one of my attempts had a clock that would advance for 90 minutes without advancing the hours. Regarding the time, it went back 15 minutes, zeroed the minutes and then looped back another 15 minutes. I have no idea why.

          Viewing 4 posts - 26 through 29 (of 29 total)
          • Please log in to reply to this topic. Registering is free and easy using the links on the menu at the top of this page.

          Advert

          Latest Replies

          Viewing 25 topics - 1 through 25 (of 25 total)
          Viewing 25 topics - 1 through 25 (of 25 total)

          View full reply list.

          Advert

          Newsletter Sign-up