View Single Post
  #3   Spotlight this post!  
Unread 23-11-2015, 20:59
jgrindle's Avatar
jgrindle jgrindle is offline
Losing Sleep
AKA: John Grindle
FRC #5122 (RobOTies)
Team Role: Programmer
 
Join Date: Nov 2014
Rookie Year: 2015
Location: Old Town, ME
Posts: 34
jgrindle will become famous soon enough
Re: Timing an LDR in C++

Quote:
Originally Posted by dubiousSwain View Post
Hmm...
I don't know much about C++, but I would start by triggering a timer function when the sensor reads black, then when the sensor reads white, write the timer function's time to a variable then use that in an elif statement (excuse my python)

something like:
Code:
void main() {
      if (sensor<black){
            startTimer();
      }
      if (sensor == white && timerStarted == true){
                if (timerValue<12600){
                        doSomething();
                }
                if (timerValue>12600){
                         doSomethingElse();
                }
         }
 }
PM me if you need anything else
Dubios you pretty much got it in terms for C++, just in a not very psuedoy pseudo code. For C++'s elif it's just
Code:
if(somethinghappens){
	dosomething;
}else if(Somethingelsehappens){
	dosomeotherthing;
}
Does the same thing as your elif, but just not as fancy or short
__________________

FRC 2015 Season: Programmer, Electrical, PIDTuner, Safety Captain
FRC 2015 Off-Season: Programmer, CAD Designer, Driver, Drive Team Coach, Electrical, Mechanical, PIDTuner

Last edited by jgrindle : 23-11-2015 at 21:00. Reason: clarification