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

Color sensor
http://robotc.net/forums/viewtopic.php?f=1&t=5932
Page 1 of 1

Author:  Erako [ Wed Jun 05, 2013 6:23 pm ]
Post subject:  Color sensor

Hello,
i need help please...

I try :

while (SensorValue[colorSensor] == BLACKCOLOR){
//test
}

Don't work???

Author:  NeXT-Generation [ Wed Jun 05, 2013 6:32 pm ]
Post subject:  Re: Color sensor

That is a functional command. Could you post your entire code?

Author:  Erako [ Wed Jun 05, 2013 7:16 pm ]
Post subject:  Re: Color sensor

Thanks for your time!

//Line reader with color
task main()
{
int moveTo = 1;
int move = 1;

while (true){
nSyncedMotors = synchAB;
do{
motorA = 50;
}while (SensorValue[colorPort] == BLACKCOLOR)

nSyncedMotors = synchNone; // On arrete la synchronisation des moteurs
do{
motorA = -moveTo;
motorB = moveTo;

moveTo = moveTo + move;
if (SensorValue[colorPort] != BLACKCOLOR){
motorA = moveTo;
motorB = -moveTo;

moveTo = moveTo + move;
}
}while (SensorValue[colorPort] != BLACKCOLOR)
}
}

Author:  NeXT-Generation [ Wed Jun 05, 2013 7:53 pm ]
Post subject:  Re: Color sensor

Next time please use the
Code:
[code][/code]
tags when posting code. :wink:

You had some syntax errors in the code, and never defined the port that the sensor was on. I got it to the point where there were no errors, but no guarantees that it's bug free.

Code:
#pragma config(Sensor, S1,     colorPort,               sensorCOLORFULL)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

//Line reader with color
task main()
{
   int moveTo = 1;
   int move = 1;

   while (true){
      nSyncedMotors = synchAB;
      do{
         motor[motorA] = 50;
      }while (SensorValue[colorPort] == BLACKCOLOR);

      nSyncedMotors = synchNone; // On arrete la synchronisation des moteurs
      do{
         motor[motorA] = -moveTo;
         motor[motorB] = moveTo;

         moveTo = moveTo + move;
         if (SensorValue[colorPort] != BLACKCOLOR){
            motor[motorA] = moveTo;
            motor[motorB] = -moveTo;

            moveTo = moveTo + move;
         }
      }while (SensorValue[colorPort] != BLACKCOLOR);
   }
}

Author:  Erako [ Thu Jun 06, 2013 4:12 am ]
Post subject:  Re: Color sensor

Thank you! :D

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