Operácie

Acrob043

Z SensorWiki

Verzia z 09:48, 20. marec 2013, ktorú vytvoril Balogh (diskusia | príspevky) (3. Processing software)

Software for Color Sensors

1. Basic demonstration


2. Color Matching Demo software

Following Arduino code works with an original Parallax (or PhiPi) ColorDemo.exe program available at the following address: http://www.parallax.com/Portals/0/Downloads/docs/prod/sens/ColorPAL_programs.zip

ColorMatchDemoExe.png


3. Processing software

ColorProcessingDemo.png
// Demonstration program for Color Sensors
// TCS 230 sensor requires TCS230_Demo03_SS_CIM.bs2
// ColorPAL sensor requires ColorPAL_Demo03_SS_CIM.ino with line 78 uncommented
//
// SS_CIM 2013
// Richard Balogh

import processing.serial.*;

int lf = 10;    // Line Feed in ASCII
int cr = 13;    // Carriage Returin in ASCII

int val = 0;    // To store data from serial port, used to color background
int r,g,b,c;    // Used to color background
Serial port;    // The serial port object

void setup() {
  size(200,200);             // Size of canvas
  
 println(Serial.list());     // List of available ports
  
                             // Use the port (CHANGE THIS according YOUR PC!)
 port = new Serial(this, Serial.list()[3], 9600); 
}

void draw() {
        // The serial data is used to color the background.   
 background(r,g,b); 
}




// Called whenever there is something available to read

void serialEvent(Serial port) {

  // Data from the Serial port is read in serialEvent() 
  // using the readStringUntil() function with LF as 
  // the end character.

  String input = port.readStringUntil(lf); 
  
  if (input != null) {
    // Print message received
    println( "Receiving:" + input);
    
   // The data is split into an array of Strings with 
   // a comma as a delimiter and converted into an 
   // array of integers.
   int[] vals = int(splitTokens(input, ",")); 
    
    // Fill r,g,b variables
    r = vals[0];
    g = vals[1];
    b = vals[2];
    c = vals[3];
  
    /* ************************************* */
    /*                                       */
    /*    Here is place for Your code!!!     */
    /*                                       */
    /* ************************************* */
    
     println( "R:" + r);
     println( "G:" + g);
     println( "B:" + b);
     println( "C:" + c);

  }
}