int servoPin = 9;
int photoresistorPin = A0;
// Define variables
int photoresistorValue;
int angle = 0;
int totalEnergy = 0;
const int UPDATE_INTERVAL = 5000;
void setup() {
// put your setup code here, to run once:
// Attach the servo
pinMode(servoPin, OUTPUT);
servo.attach(servoPin);
digitalWrite(ledOnPin, HIGH);
digitalWrite(ledOffPin, HIGH);
// Start serial communication
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
photoresistorValue = analogRead(photoresistorPin);
angle = map(photoresistorValue, 0, 1023, 0, 180);
servo.write(angle);
int energyGenerated = map(photoresistorValue, 0, 1023, 0, 1000); // not sure if this would work.
Serial.print("Instantaneous power generated: ");
Serial.print(energyGenerated);
Serial.println("mW: ");
totalEnergy += energyGenerated;
delay(UPDATE_INTERVAL);
void printTotalEnergy() {
Serial.print("Total energy generated: ");
Serial.print(totalEnergy);
Serial.println("mWh: ");
//For telling which mode the solar cell is in, tracking mode or stationary
if (switchValue == HIGH) {
digitalWrite(ledOffPin, LOW);
if (ledState == LOW) {
digitalWrite(ledOnPin, HIGH);
ledState = HIGH;
}
}
else {
digitalWrite(ledOnPin, LOW);
if (ledState == HIGH) {
digitalWrite(ledOffPin, HIGH);
ledState = LOW;
}
}
}
}