top of page

RGB Color Sensor Demo 2

This program is for the RGB color sensor, and plots the clear, red, green and blue color values as vertical bars on the show page.

Program


---

RGB Color Sensor Demo 2

---


prog_vars =

d/red_line 0

d/green_line 0

d/blue_line 0

d/clear_line 0

prog_vars.


prog_start =

pclear

d1000

ptl 10 5 ^ts=24^ "RGB Color Sensor Demo Program"

-- Enable the I2c system

i2con

-- Display the Quit button

pb 400 20 ^n=Quit^p=exitnow^

prog_start.


prog_loop =

-- main program loop


-- Invert the values so the bars go up

sub -1 /cs_clear -> /clear_line

sub -1 /cs_red -> /red_line

sub -1 /cs_green -> /green_line

sub -1 /cs_blue -> /blue_line


-- Display the colors as vertical bars

pvl 25 300 /clear_line ^lc=yellow^lw=20^

pvl 75 300 /red_line ^lc=red^lw=20^

pvl 125 300 /green_line ^lc=green^lw=20^

pvl 175 300 /blue_line ^lc=blue^lw=20^


-- Display the values

ptl 15 300 ^ts=16^ "/cs_clear"

ptl 65 300 ^ts=16^ "/cs_red"

ptl 115 300 ^ts=16^ "/cs_green"

ptl 165 300 ^ts=16^ "/cs_blue"


-- Set the USER 1 LED to the color.

l1 /cs_red /cs_green /cs_blue


prog_loop.

prog_stop =

ptl 100 200 ^ts=75^ "Bye"

prog_stop.



bottom of page