//Created by Barbu Vulc.
//This is a simulation of an solar tracker using an Arduino UNO R3.
/* 
  We have 2 LDR sensors and 1 servo motor. In real life when more light is going down
  on either one of the sensors, the solar panel will rotate in that direction.
  In this example, the hypothetical solar panel rotates only on one axis!
*/
//Servo library:
#include <Servo.h>
Servo SM; //Servo object...
const int servoPin = 2;

//Define variables for the 2 photoresistors:
const int sensorMin1 = 0;   //Sensor minimum...
const int sensorMax1 = 100000; //Sensor maximum...
const int sensorMin2 = 000;   //Sensor minimum...
const int sensorMax2 = 100000; //Sensor maximum...

void setup() {
  //Attach SM to pin 2 to the Arduino UNO board!
  SM.attach(2);
}

void loop() {
  //The photoresistor variable...
  int LDR1 = analogRead(A0);
  //0-600 (LDR sensor values) -> 0-180 (Servo Motor values(degrees))...
  uint16_t angle1 = map(LDR1, 0, 100000, 0, 90);
  //Record the now-adjusted value of the sensor to the servo motor.
  int LDR2 = analogRead(A1);
  uint16_t angle2 = map(LDR2, 0, 100000, 91, 180);
  SM.write(angle1);  SM.write(angle2);
}



//Representation:

//             /######/######/######/######/######/
//            /######/######/######/######/######/
//           /######/######/######/######/######/
//          /######/######/######/######/######/
//         /######/######/######/######/######/
//        /######/######/######/######/######/
//       /######/######/######/######/######/
//      /######/######/######/######/######/
//     /######/######/######/######/######/
//                         |  |
//                         |  |
//                         |  |   <--
//                        /|  |\      \
//                       |\|__|/|      | The axis
//                        \|  |/      /
//                         |  |   <--
//                         |__|
$abcdeabcde151015202530354045505560fghijfghij