Go Down

Topic: How to program ATmega328P Microcontroller for 2 Axis Control (Read 709 times) previous topic - next topic

kenwood120s

Quote
// Try searching maximum pages, now page 40, then 1 at a time - I know of no other way. //
If that was at me, here's how to link to a thread. Open the thread you want to be able to link to, then select and ctrl-C its URL. Then in the post you want to link from, select the text in your post you want to use as the clickable link, and hit the "chain" icon. Ctrl-V your previously ctrl-C'd url in where it says "Enter URL", and hit OK there and on the next panel.



So for example you can now click here to go to one of your other threads, which may or may not be the one you were talking about because I cba to track that one down.


JackOWalden1Sr

/* The below code is in the public domain. With the controller board powered up,
with 5 volts, will allow for the uploading of code to the board via computer.
The below 'serial' code will now be in memory, and will light the internal led?
 // kenwood120s, I'm sorry for not mentioning your name, and I know not how to
 re-open a closed thread
 // Keep in mind the pull-up means the pushbutton's logic is inverted. It goes
 // HIGH when it's open, and LOW when it's pressed. Turn on pin 13 when the
 // button's pressed, and off when it's not:
The additional code is what I want to do:  
 // When digitalWrite(5, LOW); is low,- means 'system is not 'on control'
 // System must be manually aimed at the sun, digitalRead(A5, LOW); must be 'HIGH'
 // When digitalWrite(6, HIGH); is high, motor is energized- means 'off control'  
 // When digitalWrite(6, LOW); is low, motor is deenergized- means 'on control'  
 // etc.. please indicate, yes or no, if I'm on the right path. It compiles?
 // Why sensorVal seems to work, when digitalRead don't?
 // Why error "exit status 1   expected '}' at end of input */

void setup() {
 //start serial connection
 Serial.begin(9600);
 //configure pin 2 as an input and enable the internal pull-up resistor
 pinMode(2, INPUT_PULLUP);
 pinMode(13, OUTPUT);
}

void loop() {
 //read the pushbutton value into a variable
 int sensorVal = digitalRead(2);
 //print out the value of the pushbutton
 Serial.println(sensorVal);
 //print out the value of the input sensor
 int digitalRead(A0);

 if (sensorVal == HIGH) {
   digitalWrite(13, LOW);
 } else {
   digitalWrite(13, HIGH);

 if (sensorVal, A0 == HIGH) {
   digitalWrite(5, LOW);
 } else {
   digitalWrite(5, LOW);
   
 if (sensorVal, A1 == HIGH) {
   digitalWrite(6, HIGH);
 } else {
   digitalWrite(6, LOW);
}

BJHenry

Quote
// Why sensorVal seems to work, when digitalRead don't?
Because this:
Quote
Code: [Select]

 int sensorVal = digitalRead(2);

 if (sensorVal == HIGH) {
   digitalWrite(13, LOW);
 } else {
   digitalWrite(13, HIGH);
is different to this:
Quote
Code: [Select]

 if (sensorVal, A0 == HIGH) {
   digitalWrite(5, LOW);
 } else {
   digitalWrite(5, LOW);
 
Quote
Why error "exit status 1   expected '}' at end of input */
Because you're missing several closing braces.

kenwood120s

I know not how to re-open a closed thread
Threads typically don't get closed, but what's closed threads got to do with this? I merely suggested a way to link to an existing thread from a post, in a way that's better than saying it's on page X of a forum, since it won't be on that page for long.

PLEASE us code tags: you have used them before so you know how, but just check you don't include your post inside the tags.

//Posting as comments like this is crazy.

(And in any case the //s are redundant since you use the /*...*/ approach ;) )

JackOWalden1Sr

Thanks BJHenry, now I'm getting the hang of opening and closing braces; and how to do it automatically, with a quick 'enter'.  Also, thanks kenwood120s, for your good input.  :)

JackOWalden1Sr

What I have is a dual axis control system that can be more accurate than NASA's solar control. It will keep the dual axis platform aimed directly at the sun for maximum output of the solar cells. The control system can be as accurate as desired, and will even keep it out of the shade of adjacent platforms.
The earth is not round, it is slightly bulging at the equator; it is also tilted, and it wobbles somewhat. This is what causes the annual summer and winter solstices and equinoxes. Nothing 'solar' is exact, only close.
The control system can track the sun by time alone; but, if not exactly by time, then by sensor input. This will take into consideration the solstices and equinoxes year round.
The timing can be based on the longest day at the installed location worldwide.  The altitude is controlled 'UP' in the a.m. and 'DOWN' in the p.m. hours. This is based on pre-and-post Solar Noon, not 12:00 o'clock noon, as the days are longer or shorter at varying locations. The following URL is for the Global Positioning System (GPS}. https://www.esrl.noaa.gov/gmd/grad/solcalc/ It is ideal for determining the sunrise and sunset times, but, if the programming code could be embedded in the Microcontroller's memory it would be much better. Even without that feature, GPS is still worthwhile for locating the systems anywhere on earth. It is not considered at this time to rotate the platform continuously, but, park it in the east at the very end of day.
I have a new code ready for posting, if you are ready to consider it. This code is based on melding two codes together, and removing the superfluous code. The code has a myriad of timed outputs, in lieu of just one.  Any and all inputs as to the cause will be greatly appreciated. Thanks, and have a nice day. 

BJHenry

Feel free to post your new code, but if you still haven't gone back and gotten the basic down then you'll just get told again to do so.

Go Up