'{$STAMP BS2} '{$PBASIC 2.5} ' StampPlot Example for the TAOS TCS230 Color Sensor ' Adapted by Martin Hebel - SelmaWare Solutions ' www.stampPlot.com ' The StampPlot macro used to run this code in not ' very important. All the code to plot the data is sent ' from the BASIC Stamp. The StampPlot macro configuration ' simply has some other beneficial features. 'Define port pins EN CON 1 A0 CON 2 S0 CON 3 S1 CON 4 S2 CON 5 S3 CON 6 nLED CON 7 OUT CON 8 'Define count periods for each color. 'Adjust these for a reading just under 255 ' for a white sheet of paper. pRED CON 12 pGREEN CON 8 pBLUE CON 6 'Define variables for color results. RED VAR Word GREEN VAR Word BLUE VAR Word 'Program starts here. PAUSE 1000 ' Wait for StampPlot connection to stabilize Start: LOW A0 'For Unit 0; use high for Unit 1. HIGH S0 'Maximum output rate. HIGH S1 ' " LOW nLED 'Turn on LED. HIGH EN 'Enable sensor output. DEBUG CR,"!AWTH 3",CR DO: GOSUB Color ' Get the color data. GOSUB PlotIt ' Plot Data PAUSE 100 ' Small pause to allow StampPlot to keep up LOOP 'Color: Read all three color components. Color: LOW S2 'Address the red output. LOW S3 COUNT OUT, pRED, RED 'Read the red component. Red = Red MAX 255 ' max at 255 for hex color data HIGH S3 'Address the blue output. COUNT OUT, pBLUE, BLUE 'Read the blue component. Blue = Blue MAX 255 HIGH S2 'Address the green output. COUNT OUT, pGREEN, GREEN 'Read the green component. Green = Green MAX 255 RETURN PlotIt: DEBUG "!ACHN 0,", DEC Red,",(Red)",CR ' plot amount of red on channel 0 in red DEBUG "!ACHN 1,", DEC Green,",(Green)",CR ' plot amount of green on channel 0 in green DEBUG "!ACHN 2,", DEC Blue,",(Blue)",CR ' plot amount of blue on channel 0 in blue ' Draw a filled rectange at top of plot based on time in composite color of hex RGB DEBUG "!FREC L9,90a,T9,100a,", HEX2 BlUE, HEX2 GREEN, HEX2 RED, CR ' Update bar and color value boxes DEBUG "!O UPDATE",CR ' If Log Data check is checked, write hex and decimal colors to file DEBUG "!IFTH (ChkLog),=,1,!LOGD ",HEX2 BlUE, HEX2 GREEN, HEX2 RED, ",", DEC Red, ",", DEC Green, ",", DEC Blue,CR RETURN