hi i have a script that i am working on for a Sun tracker/Light Tracker sensing light through Light Resistant Diodes (think that is what they are called) my problem is that the diodes are putting out different readings andy way her is the scrip that i have so far
#include <SoftwareSerial.h>
#include <Stepper.h>
int LED = 12; //includ a light that is in port 12
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution for your motor
const int enableA = 6;
const int enableB = 5;
Stepper myStepper(stepsPerRevolution, 4, 7, 3, 2); // initialize the stepper library using the default pins on the HBridge Shield:
void setup() {
Serial.begin(9600);
pinMode(LED, OUTPUT);
pinMode(enableA, OUTPUT);
pinMode(enableB, OUTPUT);
myStepper.setSpeed(200);
}
void loop() {
int sensorValue1 = analogRead(1); // add a LRD to analogRead (1)
int sensorValue2 = analogRead(2); // add a LRD to analogRead (2)
Serial.print(sensorValue1); //print out sensorValue1 reading of the incoming light
Serial.print("\t");
Serial.println(sensorValue2); //print out sensorValue2 reading of the incoming light
Serial.print("\t");
if (sensorValue1 > sensorValue2) // if sensorValue1 has more light than sensorValue2 do the below
{
Serial.println("clockwise");
Serial.print('\t');
digitalWrite (LED, HIGH);
digitalWrite(enableA, HIGH);
digitalWrite(enableB, HIGH);
myStepper.step(stepsPerRevolution);
}
else
{
digitalWrite(enableA, LOW);
digitalWrite(enableB, LOW);
digitalWrite (LED, LOW);
}
if (sensorValue2 > sensorValue1) // if sensorValue2 has more light than sensorValue1 do the below
{
Serial.println("counterclockwise");
Serial.print('\t');
digitalWrite(enableA, HIGH);
digitalWrite(enableB, HIGH);
myStepper.step(-stepsPerRevolution);
digitalWrite (LED, HIGH);
}
else
{
digitalWrite(enableA, LOW);
digitalWrite(enableB, LOW);
digitalWrite (LED, LOW);
}
delay(500);
}
so how do i make so that if the LRD are in a particular percentage of each other do nothing?