View unanswered posts | View active topics It is currently Fri Nov 22, 2019 10:56 am






Reply to topic  [ 2 posts ] 
Light sensor reading too quickly 
Author Message
Rookie

Joined: Fri May 01, 2015 12:28 pm
Posts: 1
Post 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);
      }
   }
}


Fri May 01, 2015 12:50 pm
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 722
Post 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

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our updated help documentation and the ROBOTC Forums.


Mon May 11, 2015 12:29 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.