econjack:
@Delta_G: do you know an easy way to do that?
I'm not Delta_G, but my Google told me to use perhaps:
https://www.gonnalearn.com/code/remove_line_numbers_from_code.htm
The result is:
/*
Solar Tracker
tracks sun in two axis for solar energy applications
requirements for built: (5V Hobby Servo [PIN9], 4 LDRs [PIN A0, A1], 4 10kOhm Resistors [Pulldown for LDR], Jumperwires), cardboard
Copyright (C) 2012 Bernd Klein
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <Servo.h>
// 2 new servo object
Servo tiltServo;
Servo yawServo;
// define pins
// A0.. A4 for LDR and pulldown resistor
const int ldrUp = A0;
const int ldrBottom = A1;
const int ldrLeft = A2;
const int ldrRight = A3;
// define global variables
//int switchVal = 0;
int posTilt = 90;
int posYaw = 90;
void setup() {
// attach tiltServo to digital PWM pin 9 an yawServo to digital PWM 10
tiltServo.attach(10);
yawServo.attach(9);
// serial monitor with BAUD 9600 for monitoring the LDR outputs for debugging
Serial.begin(9600);
}
void loop() {
// goto pos (middle)
tiltServo.write(posTilt);
yawServo.write(posYaw);
// save LDR values in variabels
int ldrUpValue = analogRead(ldrUp);
int ldrBottomValue = analogRead(ldrBottom);
int ldrLeftValue = analogRead(ldrLeft);
int ldrRightValue = analogRead(ldrRight);
// print LDR variables in serial console for debug an calibration
Serial.print("LDR Up = " );
Serial.print(ldrUpValue);
Serial.print("\t LDR Down = ");
Serial.println(ldrBottomValue);
Serial.print("\t LDR Left = " );
Serial.print(ldrLeftValue);
Serial.print("\t LDR Right = ");
Serial.println(ldrRightValue);
// wait 10 ms
delay(10);
// delta of LDR values
int deltaTilt = ldrUpValue - ldrBottomValue;
int deltaYaw = ldrLeftValue - ldrRightValue;
// define buffer, you might use two buffers one for yaw one for tilt
int buffer = 100;
// TILT Loop
// while sun nor perpendicular move by increasing pos and go to new position
while (deltaTilt > buffer) {
posTilt = posTilt++;
tiltServo.write(posTilt);
delay(50);
break;
}
// while sun not perpendicular move by decreasing pos and go to new position
while (deltaTilt < -buffer) {
posTilt = posTilt--;
tiltServo.write(posTilt);
delay(50);
break;
}
//YAW Loop
// while sun nor perpendicular move by increasing pos and go to new position
while (deltaYaw > buffer) {
posYaw = posYaw++;
yawServo.write(posYaw);
delay(50);
break;
}
// while sun not perpendicular move by decreasing pos and go to new position
while (deltaYaw < -buffer) {
posYaw = posYaw--;
yawServo.write(posYaw);
delay(50);
break;
}
}
The code compiles without errors, but Arduino 1.6.5 creates some "warnings", so perhaps the programming logic is not fully correct.