Program not running

while(a1<0){
val=0;
a1; // <<<<<<<<<<<<<<<
myservo.write(val);
}

When a1 is fetched from memory the status register flags will be updated so might "escape" the while loop. An ISR somewhere?

it is not a pin number. I am writing a zero on the yellow line of a micro servo SG90. if I later write 180 the servo will move 180 degrees, its max movement. and you can write anything in between to get the degree of movement you want.
There is no pin 1. a1 is the elevation of the sun as determined by my program. The elevation of the sun is negative at night. when the sun rises a1 is not negative and the program gets out of the while loop.
The project is a sun tracker, both elevation and azimuth of the sun. Very accurate and needs no external references such as GPS etc. Completely independant of external sources. The only inaccuracies may be in my conversion to servo movements.
I will try a software reset after the long overnight delay so I don't have to use a computer usb connection to get the reset.

How and where is a1 updated ?

Like otherones try to indicate:

If your program is in this while loop, normally no other code is executed to update a1 and then it never will come out again.

Only if an interrupt routine is programmed, which updates a1, then there is a chance, that this makes sense. There was already the question about an ISR in your program. If this is not existing, then this while loop most likely doesn’t make sense.

Is there a interrupt routine?
Where is your code?

Please don’t let us only guess around.

hi @petercl14

your code could even have 3000 lines with each line containing 40 characters.
If you post your complete sketch as a code-section the height will be the half a computer screen.

Any texteditor has a search function where "a1" can be typed in to find where in thousands of lines your variable "a1" is used.

And with this simple technique your code can be analsysed.

You can go on for weeks with small text postings or code-snippets and loose the voluntary help of all users here still having not solved your problem.
or

You simply post your most actual and complete sketch as a code-section.
If you read this 3 minutes tutorial how to do it you will have posted your most actual and complete sketch with 5 mouse-clicks and 5 keypresses well fomatted as a code-section.

So what the hell is so complicated about doing this?

the elevation of the sun at my location is the angle the sun makes with my horizon. it is specific to my location. when the sun is at geographic north the elevation is 90 degrees. when at sunrise or sunset the elevation is zero.
my program updates the value of a1. a1 in the while statement allows the program to get out of the while statement when the sun is no longer below the horizon.
If you used an 'if' statement you would be running into the rest of the program. The while statement makes sure nothing happens in the program until the sun again rises above the horizon.
the elevation of the sun is measured relative to your particular horizon.

Please answer this question

while(a1<0){
val=0;
a1;
myservo.write(val);
}

If a1 is a variable, then the line
a1;
does nothing!

As far as I understand, you observe, that your program doesn´t come out of this while loop. This looks absolute plausible!
The program (ones entert) should be cought in this loop for ever! It´s exactly what is programmed there!

what is so hard about posting your complete sketch?

If you really would post your complete sketch

  • does your head explode?
  • does your desk catch fire?
  • will it cause an earthquake?
  • will all your hair suddenly drop from your head?

what are you saying? This will all not happen?
Are you sure? Are you really sure??

So what the heck is the problem with posting your complete sketch?

How do you know the accuracy if you haven't got it working yet?

If you have a real time clock, why do you need to reset each day?

Tom.... :smiley: :+1: :coffee: :australia:

Hi, @petercl14

Does your algorithm allow for the different sunrise and sunset times;

On the summer solstice, Ballarat experiences its longest day of the year. The sun rises at approximately 6:06 AM and sets at around 8:49 PM, resulting in about 14 hours and 42 minutes of daylight.

During the winter solstice, Ballarat has its shortest day. The sun rises at approximately 7:37 AM and sets at around 5:25 PM, providing about 9 hours and 48 minutes of daylight.

Gaisma

Tom.... :smiley: :+1: :coffee: :australia:

Hi, @petercl14
If you are serious about your project?

Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

Please post your code.

Please take the time to do this.
WHY..
Because it will help us understand your project and help with suggestions.

Tom.... :smiley: :+1: :coffee: :coffee: :coffee: :australia:

No, it doesn't. Not if that is your actual code and you don't update a1 in an ISR.
the line

a1;

does nothing

the best way I can reply to your question is this. there is an app on the internet called the suns position at my location. get this app. it will give you the suns azimuth(direction of sun relative to true north). it also will give you the elevation of the sun relative to your local horizon.
my program(sketch) for my location gives exactly the same results as the app for my location. you will see from the app that a1(my symbol for the suns elevation) constantly changes over time.
my complete sketch does this without any reference to outside sources such as satellite or internet.the maths is very complicated which is why I don't want to burden you guys with my full sketch(program).

Put your az/el calculator into a function/library, that way it won't clutter up the main part of your code.
Do you understand why this will not work as you want it to?

while(a1<0){
val=0;
a1;
myservo.write(val);
}

Tom.. :smiley: :+1: :coffee: :australia:

Sorry, but that does not explain how and where a1 varies in your sketch, whatever its meaning or purpose. As a result I don't see how the while loop will ever end

Where does your sketch get the value of a1 from ?

3 days ago, 32 posts ago you have been asked the first time to post your complete sketch.

The reason is this
this is your code-snippet

while(a1<0){
val=0;
a1;
myservo.write(val);
}

compare it with this code-snippet

while(a1<0){
val=0;
a1 = myMysterius_value_assigning_to_variable_a1
myservo.write(val);
}

what difference do you see??

Since we all have fun to try to extract from an already not interested TO some sens, I will just for the fun add another possibility to the discussion:

#define a1 myMysteriousFunction()

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