Hey there,
the last two hours I’ve tried to get the NXT Color Sensor to read some colors, but it didn’t work so well. I
The program below prints for each color a “1”. I’ve tried using the other possibilities:
ReadAsString() – prints an “Black” for each color
Read() – prints an “1”
and ReadRGB.. well, how do i save it ? Won’t work with int, byte, string, char… ?
using System;
using System.Threading;
using MonoBrickFirmware.Sensors;
using MonoBrickFirmware.Movement;
using MonoBrickFirmware.Display;
using MonoBrickFirmware.UserInput;
namespace AMotorcolor
{
class Program
{
static void Main(string[] args)
{
NXTColorSensor sens = new NXTColorSensor(SensorPort.In1);
Motor motorA = new Motor(MotorPort.OutA);
int farbe1, farbe2;
LcdConsole.WriteLine("Scanne Farbe 1..."); // reading the first color
Thread.Sleep(500);
farbe1 = sens.ReadRaw();
LcdConsole.WriteLine("Farbe 1 = " + farbe1);
Thread.Sleep(4000);
LcdConsole.WriteLine("Scanne Farbe 2..."); // reading the second color
Thread.Sleep(500);
farbe2 = sens.ReadRaw();
LcdConsole.WriteLine("Farbe 2 = " + farbe2);
Thread.Sleep(4000);
LcdConsole.WriteLine("PROGRAMMENDE...");
Thread.Sleep(1000);
motorA.Off();
}
}
}
Thanks in advance..
auctor
Follow