Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ambient color doc errors #1204

Open
ricknun opened this issue Jan 24, 2022 · 0 comments
Open

ambient color doc errors #1204

ricknun opened this issue Jan 24, 2022 · 0 comments

Comments

@ricknun
Copy link

ricknun commented Jan 24, 2022

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()
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant