ROBOTC.net forums
http://robotc.net/forums/

Light sensor reading too quickly
http://robotc.net/forums/viewtopic.php?f=11&t=11043
Page 1 of 1

Author:  golden_warrior5 [ Fri May 01, 2015 12:50 pm ]
Post subject:  Light sensor reading too quickly

I need a light sensor to move a servo for about 1.5 seconds and then go back to the previous value. The value <600 only exists for about 0.2 seconds but the servo needs to wait before going back to the default position -40. In the example code, the servo does not move, even when the light sensor value is well under 600. I am wondering if there is a way to temporarily store light sensor values or if there is a way to give the servo time to react before reverting to -40.

Code:
#pragma config(Sensor, in1,    light,          sensorReflection)
#pragma config(Motor,  port3,           flap,          tmotorServoStandard, openLoop)


task main()
{
while(true)
   {
      if (SensorValue(light) < 600)
      {
         setServo(flap, -20);
         wait(1);
      }
      else
      {
         setServo(flap, -40);
      }
   }
}

Author:  JohnWatson [ Mon May 11, 2015 12:29 pm ]
Post subject:  Re: Light sensor reading too quickly

Yup, there is a way to store a value and retrieve it later; through the use of variables. Variables are one of the most powerful tools in a programmer's toolbox, and can be used for many, many things. You can find more information on variables (with a couple of examples on how to use them) in the VEX Cortex Video Trainer using ROBOTC (link below).

VEX Cortex Video Trainer using ROBOTC - Values and Variables: http://www.education.rec.ri.cmu.edu/pro ... ning3.html

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/