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

How do you program a Hitechnic color sensor V2?
http://www.robotc.net/forums/viewtopic.php?f=41&t=5678
Page 1 of 1

Author:  ddwear [ Sun Apr 07, 2013 7:57 pm ]
Post subject:  How do you program a Hitechnic color sensor V2?

Just curious on how to program it. Does anyone know?

Author:  Coder A [ Sun Apr 07, 2013 8:59 pm ]
Post subject:  Re: How do you program a Hitechnic color sensor V2?

Unless you want to do it yourself, there are a few third-party sensor drivers. I recommend Xander's drivers. I wish I knew the link.

Author:  mightor [ Mon Apr 08, 2013 12:42 am ]
Post subject:  Re: How do you program a Hitechnic color sensor V2?

You can find the driver suite here: [LINK]. The examples are hitechnic-colour-v2-test1.c and hitechnic-colour-v2-test2.c. The driver is hitechnic-colour-v2.h. Installation instructions can be found on that page as well. make sure you follow them.

Just make sure you download and install ROBOTC 3.60 if you want to use this driver suite.

= Xander

Author:  ddwear [ Wed Apr 10, 2013 7:40 pm ]
Post subject:  Re: How do you program a Hitechnic color sensor V2?

Can you give me a example of a code i would use to get it to stop on red?

Author:  mightor [ Thu Apr 11, 2013 2:23 am ]
Post subject:  Re: How do you program a Hitechnic color sensor V2?

Here's some code:

Code:
#pragma config(Sensor, S1,     HTCS2,          sensorI2CCustom)
#pragma config(Motor,  motorA,          LEFT,          tmotorNXT, PIDControl, encoder)
#pragma config(Motor,  motorB,          RIGHT,         tmotorNXT, PIDControl, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

/**
* Xander Soldaat (xander_at_botbench.com)
* 11 April 2013
* version 0.1
*/

#include "drivers/hitechnic-colour-v2.h"

task main () {
  int _color = 0;

  nxtDisplayCenteredTextLine(0, "HiTechnic");
  nxtDisplayCenteredBigTextLine(1, "Color V2");
  nxtDisplayCenteredTextLine(3, "Test 3");
  nxtDisplayCenteredTextLine(5, "Connect sensor");
  nxtDisplayCenteredTextLine(6, "to S1");
  wait1Msec(2000);

  eraseDisplay();

  // Start the motors
  motor[LEFT]  = 50;
  motor[RIGHT] = 50;

  while (true) {

    // Read the currently detected colour from the sensor
    // You can find a list of all the colours here:
    // http://www.hitechnic.com/cgi-bin/commerce.cgi?preadd=action&key=NCO1038
    _color = HTCS2readColor(HTCS2);

    // If colour == -1, it implies an error has occurred
    if (_color < 0) {
      nxtDisplayTextLine(4, "ERROR!!");
      wait1Msec(2000);
      StopAllTasks();
    }

    nxtDisplayCenteredTextLine(0, "Color: %d", _color);

    // if the colour is red (8), stop the motors and exit while loop
    if (_color == 8)
    {
      motor[LEFT]  = 0;
      motor[RIGHT] = 0;
      PlaySound(soundBeepBeep);
      while(bSoundActive)
      {
        wait1Msec(100);
      }
      break;
    }
    wait1Msec(50);
  }
}

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