I try to get the value "lightVal" that's read from my photoresistor into the following equation:
theta = (260/3) log(23/1023)(1- lightval/1023), where theta is the steps taken by the motor. Then I need to get the servo motor to spin by theta degrees.
//locate pins
int PhotoresistorPin = A0;
//Declare global variables
int lightVal;
void setup() {
//Set photoresistor as input
pinMode(PhotoresistorPin, INPUT);
//serial is used to communicate with the board.
//Serial.begin() sets data rate in bits per second
Serial.begin(9600);
}
void loop() {
//read input from photoresistor
//analogueRead function reads the voltage across the photoresistor
lightVal = analogRead(PhotoresistorPin);
//print input from photoresistor
Serial.println(lightVal);
delay(1000);
}
I got stuck here, what do I do now? Basically, each time I try to write the equation, it tells me that "theta was not declared in this scope". Thanks!
Edit: it does not really make sense, but here it is
{ Serial.begin(9600);
for (int i =0; i<=180; i=i+180)
{ float angle = (260/3)log(23/1023,(1-(lightVal/1023);
servo.write(angle);
delay(5);
}
}