This code used to work, now it gives me errors when I try to compile it.

This is code to drive a NeoPixel clock.

I have 4 of the big quarter circle pieces to make a circle (60 LEDs) and so a clock.

When "Daylight saving" starts/ends it is supposed to adjust itself.
I never really got it working but it wasn't a big deal.
Normally it is just plugged into power. Not a computer.
I would simply plug it into a computer and update the date/time that way.

It happened again (a few days ago) and moved the time the wrong way.

Now, I can't even set the time or even compile the code.

Details:
Arduino NANO ATmega328 (Old bootloader)
CH340 USB - I believe.
That is why the OLD BOOTLOADER is set.
I found that got around the problem.
It DID work when I wrote it, or there is no way it could have been flashed into the Arduino.

This was written a long time ago and it worked.
I had to update the clock evey 6 months because of "daylight saving", but it worked.

I have notes for myself on how to set the clock. They no longer work if I send what is written there.

And yes: the code is a mess.

Maybe I should re-write it.
Maybe I should just fix what is wrong.
There is no right answer.

But it is confusing that it now just isn't talking to me at all and I can't set the time.

I see the output fine.
1 Jan 2066 - I seem to remember is the time.

What I remember:
I wanted to optimise how the output was and so the stream library was used.
So that is why it is used.

The errors I see when compiling:

/home/me/Arduino/Ring clock/Ring_Clock14ce/Time_functions.ino: In function 'void test()':
Time_functions:545:20: error: 'inChar' was not declared in this scope
     Serial.println(inChar);
                    ^~~~~~
/home/me/Arduino/Ring clock/Ring_Clock14ce/Time_functions.ino:545:20: note: suggested alternative: 'char'
     Serial.println(inChar);
                    ^~~~~~
                    char
exit status 1
'inChar' was not declared in this scope

Ring_Clock14ce.zip (15.8 KB)

Part of Time_functions.ino

  while (Serial.available())
  {
    // get the new byte:
    char inChar = (char)Serial.read();
    // add it to the inputString:
    inputString += inChar;
    // if the incoming character is a newline, set a flag so the main loop can
    // do something about it:
    if (inChar == '\n')
    {
      stringComplete = true;
    }
  }
  Serial.print("This was received ");
  Serial.println(inChar);

inChar is declared in the code block for the while loop so goes out of scope when the while loop ends, hence the error message when you try to print it

Thanks. Really.

But it raises the question for me: So how did it ever work?

Rhetorical - of course.

I'll see if I can get it working with this knowledge.

That is part of a bit of code which isn't used. But looking past that, here is the next problem which has me stumped.

I change the code to look like this:

    //Serial.println("Test routine");
    String inputString = "";
    bool stringComplete = false;
    static time_t tLast;
    time_t t;
    tmElements_t tm;
    // get the new byte:
    char inChar = (char)Serial.read();

So inchar is in the next higher level of code.

That line:

char inChar = (char)Serial.read();

It makes inChar..... (confused how to put it)
Anyway, so I do that. Now I get this error:
/

home/me/Arduino/Ring clock/Ring_Clock14ce/Time_functions.ino:550:21: warning: ISO C++ forbids comparison between pointer and integer [-fpermissive]
       if (inChar == "U"){
                     ^~~
/home/me/Arduino/Ring clock/Ring_Clock14ce/Time_functions.ino:568:21: warning: ISO C++ forbids comparison between pointer and integer [-fpermissive]
       if (inChar == "D"){

Yes, I need to learn the language, but.... to me that is confusing.

forbids comparison between pointer and integer
pointer?
integer?
inChar is a char.... I just declared that.

inChar is a char.... I just declared that.

So test it for equality with another char. Single quote marks for a single char. The double quote marks " " are for character strings, not single characters.

//if (inChar == "U"){
if(inChar == 'U'){
//if (inChar == "D"){
if (inChar == 'D'){

Thanks very much.

I am learning Javascript just now and trying to remember all this is just overload.

I shall.

But I am still perplexed how it ever worked in the past.

What I am doing now is trying to write a new input routine for setting the time.

It doesn't seem to be seeing/getting what I enter in the console - which is weird.

Again: Thanks very much.

Ok, this is weird.
Taking on what cattledog said, and while I was trying to go through the writing a test routine for serial input:
(Alas I had to use a NodeMCU board though)
I goofed when testing the compile as I had it set to the NANO by mistake.
I uploaded the sketch and it worked.
I would enter numbers separated by , and it would echo them back.
But if I made the first one 3 digits long, the code would given back a message dealing with the year value.
So, I reset the program to use the NANO board, etc and checked the compile error for my existing code which I uploaded earlier.
This is what I saw on the screen.
Now, no offence to anyone. This is just as it happened.
I reflashed the Arduino anyway - with the correct board, etc.
The input started to work and I could set the time.
How weird is that?
However: Thanks to all who replied. I do appreciate it.
It just seems my life is plagued with this thing that if I don't ask, problems will remain as is. Then a lot of the time they go away after my asking.
(This is now edited as I got an error saying the post was more than 9000 characters long)
There is also no attachment. I'll work on that soon.

Help, I can't seem to post another text only reply and not get a message about this message is too big.

Since you’re using Strings (capital S), I’d look there first.
Then I’d be looking at any array[] lengths to ensure you’re not overrunning the end.
Next, learn C coding syntax... it’s important if you’re writing in the C languages.Sorry.

Ok.

But I used a routine from the person who wrote the RTC library to set the time.

To the best of my knowledge it allows for over runs to a degree.

What really has me confused is it has worked - since about 2019. Though the "daylight savings" part is still debatable.

On Sunday when it was adjust the wrong way and I decided to do it "the hard way" - plugging it into a computer and setting the time that way - it didn't work.

NOTHING was accepted when I typed it in the console.
It used to take things if I "under ran" the input buffer and wait until enough things were received and then act on that.
(Getting a bit off topic)

But it just wasn't accepting inputs.

The code when I tried to compile it - which is exactly the same as it was when I uploaded it the previous time - gave errors I didn't understand.

Yes, I fixed that bit after being told what the problem is/was.

It complied without errors.

But I decided to dig into the routine used to set the time.

I copied the code from the original file from the person who wrote the example and made a new bit of code.

I flashed a different Arduino (MCU, not NANO) and it worked.
I then went back to the original code for the clock and after accidentally having the wrong board selected, it then complied ok with no errors like before.

Further more: I flashed it - don't know exactly why - but then it started to accept time inputs.

That's what really gets me. But I guess it is academic as it now works.

Yes, I shall try to get more C learning. But while doing JavaScript there is conflict in how things are done and it is difficult at best.

Thanks all the same.

Basic question...
Is your serial console (terminal) set for the correct speed, data/stop and parity ?
The boot loader will ‘always’ work at 115200, but you need to set the terminal to match what’s being set in setup()... Serial.begin()

But it raises the question for me: So how did it ever work?

This function(in the time functions tab) will never compile correctly. Indeed you had to correct it. Possibly if it never was called anywhere else in the program, the compiler version, in use for the original upload, decided to leave it out.

void test(){
    //Serial.println("Test routine");
    String inputString = "";
    bool stringComplete = false;
    static time_t tLast;
    time_t t;
    tmElements_t tm;
//    if (Serial.available() == 1)
//    {
      //

    while (Serial.available()){
      // get the new byte:
      char inChar = (char)Serial.read();
      //inChar = (char)Serial.read();
      // add it to the inputString:
      inputString += inChar;
      // if the incoming character is a newline, set a flag so the main loop can
      // do something about it:
      if (inChar == '\n') 
      {
        stringComplete = true;
      }
    }
    Serial.print("This was received ");
    Serial.println(inChar);


      
//      int y = Serial.parseInt();
      if (inChar == "U"){
        // UP
        Serial.println("UP");
        //Serial.println("========================");
        //  2020 10 04
        //  ==========
        tm.Year = year();
        tm.Month = month();
        tm.Day = day();
        tm.Hour = hour();
        tm.Minute = minute();
        tm.Second = second();
        t = makeTime(tm);
        tm.Hour = tm.Hour + 1;
        RTC.set(t);        //use the time_t value to ensure correct weekday is set
        setTime(t);
        //RTC.start();
      } else 
      if (inChar == "D"){
        // DOWN
        Serial.println("DOWN");
        //Serial.println("========================");
        //  2020 10 04
        //  ==========
        tm.Year = year();
        tm.Month = month();
        tm.Day = day();
        tm.Hour = hour();
        tm.Minute = minute();
        tm.Second = second();
        t = makeTime(tm);
        tm.Hour = tm.Hour - 1;
        RTC.set(t);        //use the time_t value to ensure correct weekday is set
        setTime(t);
        //RTC.start();
      }

      
//    }
}

I'm not certain where you use test() but the main time setting routine from the J Christensen library is this

void set_time_with_this()
{

Ok, catching up:

Is your serial console (terminal) set for the correct speed, data/stop and parity ?

Well, I could see the output from the Arduino in the console/window, so I would think so.

The test routine.

That was put in as a test to check/do something. It worked and I removed the call to it in the main loop.

Yes, bad programming. I'm not perfect.

I'll change the " to ' to honour the structure/syntax.

I just have to work out how to set/adjust the time at the start/end of summer time.

Again:
Thanks for the replies.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.