}
#pragma config(Sensor, S1, COLOR, sensorI2CCustom)
#include "drivers/HTCS2-driver.h" //download and include drivers for robotC websites
task main () {
int _color = 0;
int selection=0;
nxtDisplayCenteredTextLine(3, "WAIT A MOMENT!"); //"wait a moment" will be wroten in display for two seconds
wait1Msec(2000);
eraseDisplay();
while (true)
{
_color = HTCS2readColor(COLOR); //_color gets values for the sensor
if (_color < 0) //if color sensor value goes under 0, all tasks will stop.
{ //varisensorin arvon ei pitaisi menna alle 0, jos menee tulee error
nxtDisplayTextLine(4, "ERROR!!");
wait1Msec(2000);
StopAllTasks();
}
if(_color<5 && _color>3) // GREEN, Value from sensor = 4
{
selection=1;
}
if(_color<10 && _color>7) //RED, Value from sensor = 8
{
selection=2;
}
if(_color<7 && _color>5) //YELLOW, Value from sensor = 6
{
selection=3;
}
if(_color<3 && _color>1) //BLUE ,Value from sensor= 2
{
selection=4;
}
if(selection==1)
{
nxtDisplayCenteredTextLine(4, "GREEN"); //Display shows text "GREEN", 4 is a textline number
}
if(selection==2)
{
nxtDisplayCenteredTextLine(4, "RED");
}
if(selection==3)
{
nxtDisplayCenteredTextLine(4, "YELLOW");
}
if(selection==4)
{
nxtDisplayCenteredTextLine(4, "BLUE");
}
}
}
{code} |