microsoft / pxt-adafruit

Microsoft MakeCode editor for Adafruit Circuit Playground Express
https://makecode.adafruit.com
Other
81 stars 77 forks source link

ambient color doc errors #1204

Open ricknun opened 2 years ago

ricknun commented 2 years ago

Describe the bug Ambient color documentation at https://github.com/Microsoft/pxt-adafruit/blob/master/docs/reference/input/ambient-color.md has some errors.

"Returns a number that is the ambient color level from 0 (black) to 255 (white)." should say something like "Returns one of 5 possible hexadecimal 0xRRGGBB Red-Green-Blue color values: red 0xff0000, green 0x00ff00, blue 0x0000ff, yellow 0xffff00, or white 0xffffff." I can't be sure these 5 are the only values possible, but are a guess based on the description at the top of the page.

The text "When you press button A" is wrong. The posted program is a forever loop not related to button A.

The example program misses decoding white (0xffffff).

Related but not a defect: On a Circuit Playground Express the provided program flashes LED #1 every ambient light measurement whether that measurement equals a possible color or not. (Several wasted bright flashes each loop.) It would be better if the program measured ambient color once, saved the value in a variable, then decoded it to all possible colors. I also prefer triggering on a button A push as in the program header text implies instead of polling forever with bright annoying LED #1 measurement flashes. See the program below. Press button A, put a colored piece of paper in front of the device, see and hear the results, repeat. (The measured color is output to a neoPixel too.)

Additional context My Circuit Playground Express code, for consideration/editing as a replacement.

let RGB_val = 0 input.buttonA.onEvent(ButtonEvent.Click, function () { pause(1000) RGB_val = input.ambientColor() light.setPixelColor(5, RGB_val) // Test for red, green, blue, yellow, white. 5 notes // span 2 octaves by *sqrt(2) frequency steps. if (RGB_val == 0xff0000) { music.playTone(880, 500) } else if (RGB_val == 0x00ff00) { music.playTone(1245, 500) } else if (RGB_val == 0x0000ff) { music.playTone(1760, 500) } else if (RGB_val == 0xffff00) { music.playTone(2489, 500) } else if (RGB_val == 0xffffff) { music.playTone(3520, 500) } pause(1000) light.clear() })