Arduino Software
The Arduino program relies on a specific library I2C_RGBC_Reader to deal with the sensor.
Below, a cylinder is being read for identification: I highlight the most interesting parts from the four sections of the Arduino sketch or program: |
1• Call of libraries
|
#include <Wire.h> #include "I2C_RGBC_Reader.h"
|
2• Variables and constants
|
I2C_RGBC_Reader myRGBC_Reader;
|
3• The setup() procedure launches the colour reader and calls the standard calibration
|
myRGBC_Reader.begin();
myRGBC_Reader.standard(); |
4• The loop() procedure includes two key parts:
|
Serial.println("0..3 learn");
Serial.print("> colour object required\n"); while (!Serial.available()); myRGBC_Reader.memorise((command - 0x30)); |
|
myRGBC_Reader.getRGBC(r, g, b, c);
myRGBC_Reader.recognise(n, p); |
The colour n is then coded into 2 bits and sent to the TX-C.
|
case=0 no object i1=0 i2=0
case=1 blue colour i1=0 i2=1 case=2 red colour i1=1 i2=0 case=3 white colour i1=1 i2=1 |
Finally, the decoding chart on Robo Pro Program and Results should correspond exactly to this coding chart.
|
if (n==0) {
digitalWrite(out1pin, LOW); digitalWrite(out2pin, LOW); } else if (n==1) { digitalWrite(out1pin, LOW); digitalWrite(out2pin, HIGH); } else if (n==2) { digitalWrite(out1pin, HIGH); digitalWrite(out2pin, LOW); } else if (n==3) { digitalWrite(out1pin, HIGH); digitalWrite(out2pin, HIGH); } else { digitalWrite(out1pin, LOW); digitalWrite(out2pin, LOW); } |
Previous |
Next |