<HTML> 
<HEAD> 
	<TITLE>3rd Party ROBOTC Drivers</TITLE> 
<link href="tabs.css" rel="stylesheet" type="text/css"/> 
<link href="doxygen.css" rel="stylesheet" type="text/css"/> 
</HEAD> 
 
<BODY bgcolor="#ffffff" link="#000000" vlink="#000000"> 
<table width="100%" bgcolor="navy" cellspacing=0 cellpadding=1 border=0> 
<tr><td><table width="100%" bgcolor="#EEEEDD" cellspacing=0 cellpadding=3 border=0> 
<tr> 
    <td width="33%" align="left"> <img src="images/LOGO_NXT.gif" width=266 height=44 border="0" alt="Mindstorms"></td> 
    <td><b><font size="+3" color="navy">3rd Party ROBOTC Drivers</font></b></td> 
    <td align="right"> <img src="images/logo.png" width=44 height=44 border="0" alt="RobotC"></td>     
</tr> 
  <tr bgcolor="#cccc99" align="right"> 
          <td colspan=3> <font face="arial" size="-1"> [<a href=main.html>Home</a>] [<a target=_top href="https://sourceforge.net/projects/rdpartyrobotcdr/">Download</a>] [<a target=_top href="http://apps.sourceforge.net/mantisbt/rdpartyrobotcdr/my_view_page.php">Submit a bug/suggestion</a>]  [<a target=_top href="http://www.robotc.net/forums/">ROBOTC Forums</a>] [<a target=_top href="http://botbench.com">Blog</a>] [<a target=_top href="http://sourceforge.net/donate/index.php?group_id=257238">Support this project</a>]</font> </td> 
</tr> 
</table></td></tr> 
</table> 
<!-- Generated by Doxygen 1.7.2 -->
<div class="header">
  <div class="headertitle">
<h1>hitechnic-colour-v1-test1.c</h1>  </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><span class="preprocessor">#pragma config(Sensor, S1,     HTCS,                sensorI2CCustom)</span>
<span class="preprocessor"></span><span class="comment">//*!!Code automatically generated by &#39;ROBOTC&#39; configuration wizard               !!*//</span>

<span class="comment">/*</span>
<span class="comment"> * $Id: hitechnic-colour-v1-test1.c 133 2013-03-10 15:15:38Z xander $</span>
<span class="comment"> */</span>
<span class="comment"></span>
<span class="comment">/**</span>
<span class="comment"> * hitechnic-colour-v1.h provides an API for the HiTechnic Color Sensor.  This program</span>
<span class="comment"> * demonstrates how to use that API.</span>
<span class="comment"> *</span>
<span class="comment"> * Changelog:</span>
<span class="comment"> * - 0.1: Initial release</span>
<span class="comment"> * - 0.2: Changed the intro and info displayed</span>
<span class="comment"> * - 0.3: More comments</span>
<span class="comment"> * - 0.4: Removed common.h from includes</span>
<span class="comment"> *</span>
<span class="comment"> * Credits:</span>
<span class="comment"> * - Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.</span>
<span class="comment"> *</span>
<span class="comment"> * License: You may use this code as you wish, provided you give credit where it&#39;s due.</span>
<span class="comment"> *</span>
<span class="comment"> * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 3.59 AND HIGHER. </span>
<span class="comment"></span>
<span class="comment"> * Xander Soldaat (xander_at_botbench.com)</span>
<span class="comment"> * 20 February 2011</span>
<span class="comment"> * version 0.4</span>
<span class="comment"> */</span>

<span class="preprocessor">#include &quot;<a class="code" href="hitechnic-colour-v1_8h.html" title="HiTechnic Color Sensor driver.">drivers/hitechnic-colour-v1.h</a>&quot;</span>

task main () {
  <span class="keywordtype">int</span> red = 0;
  <span class="keywordtype">int</span> green = 0;
  <span class="keywordtype">int</span> blue = 0;
  <span class="keywordtype">int</span> _color = 0;
  <span class="keywordtype">string</span> _tmp;

  nxtDisplayCenteredTextLine(0, <span class="stringliteral">&quot;HiTechnic&quot;</span>);
  nxtDisplayCenteredBigTextLine(1, <span class="stringliteral">&quot;COLOUR&quot;</span>);
  nxtDisplayCenteredTextLine(3, <span class="stringliteral">&quot;Test 1&quot;</span>);
  nxtDisplayCenteredTextLine(5, <span class="stringliteral">&quot;Connect sensor&quot;</span>);
  nxtDisplayCenteredTextLine(6, <span class="stringliteral">&quot;to S1&quot;</span>);
  wait1Msec(2000);

  eraseDisplay();
  <span class="keywordflow">while</span> (<span class="keyword">true</span>) {
    <span class="comment">// Read the currently detected colour from the sensor</span>
    _color = <a name="a0"></a><a class="code" href="group__htcs.html#ga2ffe78205a159ffd11e8074665c293dc">HTCSreadColor</a>(HTCS);

    <span class="comment">// If colour == -1, it implies an error has occurred</span>
    <span class="keywordflow">if</span> (_color &lt; 0) {
      nxtDisplayTextLine(4, <span class="stringliteral">&quot;ERROR!!&quot;</span>);
      wait1Msec(2000);
      StopAllTasks();
    }

    <span class="comment">// Read the RGB values of the currently colour from the sensor</span>
    <span class="comment">// A return value of false implies an error has occurred</span>
    <span class="keywordflow">if</span> (!<a name="a1"></a><a class="code" href="group__htcs.html#ga4de07d555366975fb0673524cdec7b57">HTCSreadRGB</a>(HTCS, red, green, blue)) {
      nxtDisplayTextLine(4, <span class="stringliteral">&quot;ERROR!!&quot;</span>);
      wait1Msec(2000);
      StopAllTasks();
    }

    nxtDisplayCenteredTextLine(0, <span class="stringliteral">&quot;Color: %d&quot;</span>, _color);
    nxtDisplayCenteredBigTextLine(1, <span class="stringliteral">&quot;R  G  B&quot;</span>);

    nxtEraseRect(0,10, 99, 41);
    nxtFillRect( 0, 10, 30, 10 + (red+1)/8);
    nxtFillRect(35, 10, 65, 10 + (green+1)/8);
    nxtFillRect(70, 10, 99, 10 + (blue+1)/8);
    StringFormat(_tmp, <span class="stringliteral">&quot; %3d   %3d&quot;</span>, red, green);
    nxtDisplayTextLine(7, <span class="stringliteral">&quot;%s   %3d&quot;</span>, _tmp, blue);

    wait1Msec(100);
  }
}

<span class="comment">/*</span>
<span class="comment"> * $Id: hitechnic-colour-v1-test1.c 133 2013-03-10 15:15:38Z xander $</span>
<span class="comment"> */</span>
</pre></div> </div>
</div>
<hr class="footer"/><address class="footer"><small>Generated on Wed Mar 13 2013 19:56:42 for ROBOTC Drivers by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.2 </small></address>
</body>
</html>
