Shop OBEX P1 Docs P2 Docs Learn Events
Basic Stamp and Colorpal Sensor — Parallax Forums

Basic Stamp and Colorpal Sensor

JeffereyFerrantiJeffereyFerranti Posts: 4
edited 2014-05-27 07:35 in BASIC Stamp
Hello. Our colorpal can detect the colors we need it to. However, we want to have one color represent a high and the other to represent a low and these signals would go to an output pin on the microcontroller. How do we assign the variables and ranges so the sensor can detect the color and either send a high or a low. Any help appreciated. Thanks.

Comments

  • ercoerco Posts: 20,256
    edited 2014-05-23 09:05
    Do you have your Colorpal hooked up and working yet? Please attach your code so we can help.

    There is sample code available from the website.
  • JeffereyFerrantiJeffereyFerranti Posts: 4
    edited 2014-05-27 07:35
    Here is the code. It is the demo project listed on the parallax website with a few modifications.

    ' \{$PBASIC 2.5\}\par
    '\par
    ' =========================================================================\par
    \par
    '
    [ Program Description ]
    \par
    \par
    ' This program drives the Parallax ColorPAL color sensor and provides\par
    ' serial RGB data to the PC-hosted TCS230_ColorPAL_match.exe color\par
    ' matching program.\par
    \par
    \par
    '
    [ I/O Definitions ]
    \par
    \par
    sio PIN 15 ' Serial I/O com pin for ColorPAL.\par
    \par
    '
    [ Constants ]
    \par
    \par
    ' Baudrate definitions. Serial I/O must be open-drain. The ColorPAL includes\par
    ' a pullup internally.\par
    \par
    #SELECT $STAMP\par
    #CASE BS2, BS2E, BS2PE\par
    baud CON 119 + 32768\par
    #CASE BS2SX, BS2P\par
    baud CON 327 + 32768\par
    #CASE BS2PX\par
    baud CON 536 + 32768\par
    #ENDSELECT\par
    \par
    '
    [ Variables ]
    \par
    \par
    red VAR Word ' Received RGB values from ColorPAL.\par
    grn VAR Word\par
    blu VAR Word\par
    \par
    '
    [ Initialization ]
    \par
    \par
    GOSUB Reset ' Reset the ColorPAL and enter direct command mode.\par
    \par
    '
    [ Program Code ]
    \par
    \par
    SEROUT sio, baud, ["= (00 $ m) !"] 'Program ColorPAL to send $ then color data.\par
    \par
    \par
    DO\par
    \par
    SERIN sio, baud, [WAIT("$"), HEX3 red, HEX3 grn, HEX3 blu] ' Receive RGB data back.\par
    DEBUG "R", DEC4 red, " G", DEC4 grn, " B", DEC4 blu, CR ' Output it.\par
    \par
    'Changes Made\par
    \par
    OUTPUT 13\par
    \par
    IF "R" > $0010 THEN OUT13=1\par
    \par
    \par
    \par
    LOOP\par
    \par
    \par
    \par
    '
    [ Subroutines ]
    \par
    \par
    ' Reset: Sends a long break to reset ColorPAL and enter direct command mode.\par
    \par
    Reset:\par
    LOW sio 'Pull sio low to eliminate any residual charge.\par
    INPUT sio 'Return pin to input.\par
    DO UNTIL sio : LOOP 'Wait for pin to be pulled high by ColorPAL.\par
    LOW sio 'Pull pin low.\par
    PAUSE 50 'Keep low for 50ms to enter Direct mode.\par
    INPUT sio 'Return pin to input.\par
    PAUSE 10 'Pause another 10ms\par
    RETURN\par
    }

    We want the sensor to detect the color red and send a high pulse to an output when the color red is put in front of it. When red is not infront of the sensor, we want the output to be low, or 0. This needs to continuously loop as well.
Sign In or Register to comment.