View unanswered posts | View active topics It is currently Thu Apr 24, 2014 12:44 am






Reply to topic  [ 5 posts ] 
How do you program a Hitechnic color sensor V2? 
Author Message
Rookie

Joined: Thu Mar 28, 2013 12:57 pm
Posts: 2
Post How do you program a Hitechnic color sensor V2?
Just curious on how to program it. Does anyone know?


Sun Apr 07, 2013 7:57 pm
Profile
Expert

Joined: Thu Jan 03, 2013 5:10 pm
Posts: 187
Location: The plateau north of the Ohio River Valley, also known as Cave Country.
Post 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.

_________________
I'm not a robot! I'm british! ~ quote from an asparagus
I am not a robot! I am a unicorn! ~ quote from a robot
Play chess for free!


Sun Apr 07, 2013 8:59 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3116
Location: Rotterdam, The Netherlands
Post 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

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Mon Apr 08, 2013 12:42 am
Profile WWW
Rookie

Joined: Thu Mar 28, 2013 12:57 pm
Posts: 2
Post 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?


Wed Apr 10, 2013 7:40 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3116
Location: Rotterdam, The Netherlands
Post 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);
  }
}

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Thu Apr 11, 2013 2:23 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 5 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.