View unanswered posts | View active topics It is currently Tue Aug 11, 2020 9:04 pm

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

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.

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

task main()
      if (SensorValue(light) < 600)
         setServo(flap, -20);
         setServo(flap, -40);

Fri May 01, 2015 12:50 pm
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: ... 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
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest

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.