Stop and Go

The team that I am on is using a TSL230 light to frequency converter, and for the most part we have a general understanding of it. But what we are trying to do is make a servo turn so many times one way and stop when the sensor reads a "value 1" or higher and when the sensor reads "value 2" lower, the servo should turn the other way a bit and stop. But the problem we are facing is that once we reach our value 1 or 2 area, the loop will still keep going. We want the servo to activate and stop and not move until the other value is reached. Can any of y'all help us?

please post your code
makes it easier to give advice
(and please use the # button above the smileys to add code tags)

alleniiij678:
when the sensor reads "value 2" lower, the servo should turn the other way a bit and stop.

What do you mean by 'a bit'? In other words, under what conditions should it stop?

Rob- I am still learning how to use the forum here but I will post the code soon.

Peter- what I mean by a bit is that we want to servo to rotate so many times and stop. And not rotate again until the sensor reading falls into the other value's range. That is what we are trying to do

Alright here is the code that we have so far. Any help would be greatly appreciated.

// Reports the frequency from the TSL230, higher number means brighter
// Part: http://www.sparkfun.com/products/8940
// Article:  http://bildr.org/2011/08/tsl230r-arduino/ 

#include <Servo.h>
Servo myservo1;
int TSL230_Pin = 4; //TSL230 output
int TSL230_s0 = 3; //TSL230 sensitivity setting 1
int TSL230_s1 = 2; //TSL230 sensitivity setting 2

int TSL230_samples = 30; //higher = slower but more stable and accurate
boolean once;
void setup(){
  Serial.begin(9600);
  setupTSL230();
  pinMode(5,OUTPUT);
  myservo1.attach(5);
  



}


void loop(){

  float lightLevel = readTSL230(TSL230_samples);
  Serial.println(lightLevel);
boolean once;
if(lightLevel>1800 && lightLevel<10000 && once == true)
  {
   
    myservo1.writeMicroseconds(1300);delay(5000);
    myservo1.writeMicroseconds(1500);delay(5000);  
    once = false;
}

else if(lightLevel<1800 && once == false)
{
  myservo1.attach(5);
  myservo1.writeMicroseconds(1700);delay(5000);
  myservo1.writeMicroseconds(1500);delay(5000);
  once = true;
}
}

void setupTSL230(){
  pinMode(TSL230_s0, OUTPUT); 
  pinMode(TSL230_s1, OUTPUT); 

  //configure sensitivity - Can set to
  //S1 LOW  | S0 HIGH: low
  //S1 HIGH | S0 LOW:  med
  //S1 HIGH | S0 HIGH: high

  digitalWrite(TSL230_s1, LOW);
  digitalWrite(TSL230_s0, HIGH);
}



float readTSL230(int samples){
//sample light, return reading in frequency
//higher number means brighter

  float start = micros();  
  int readings = 0;

  while(readings < samples){
   pulseIn(TSL230_Pin, HIGH);
   readings ++;
  }

  float length = micros() - start;
  float freq = (1000000 / (length / samples)) * 10;

  return freq;
}

How is it that two different people have almost exactly the same question with almost exactly the same code.

Why don't you aske the moderator to combine the two Threads and save the duplication?

...R