namespace input { /**
     * Sense the ambient color using the LED pixel next to the LED sensor.
     */ export function ambientColor ( ) { const LIGHT_SETTLE_MS = 100 ; const PIXEL = 1 ; const strip = light . pixels ; const oldBrightness = strip . brightness ( ) ; const oldColor = strip . pixelColor ( PIXEL ) ; const oldBuffered = strip . buffered ( ) ; strip . setBuffered ( true ) ; strip . setBrightness ( 255 ) ; strip . setPixelColor ( PIXEL , Colors . Red ) ; strip . show ( ) ; pause ( LIGHT_SETTLE_MS ) ; const red = input . lightLevel ( ) ; strip . setPixelColor ( PIXEL , Colors . Green ) ; strip . show ( ) ; pause ( LIGHT_SETTLE_MS ) ; const green = input . lightLevel ( ) ; strip . setPixelColor ( PIXEL , Colors . Blue ) ; strip . show ( ) ; pause ( LIGHT_SETTLE_MS ) ; const blue = input . lightLevel ( ) ; strip . setBrightness ( oldBrightness ) ; strip . setPixelColor ( PIXEL , oldColor ) ; strip . show ( ) ; strip . setBuffered ( oldBuffered ) ; let c = 0 ; let mind = - 1 ; const colors = [ Colors . Red , Colors . Green , Colors . Blue , Colors . Yellow , Colors . White ] ; for ( let i = 0 ; i < colors . length ; ++ i ) { const kc = colors [ i ] ; const dr = red - ( ( kc >> 16 ) & 0xFF ) ; const dg = green - ( ( kc >> 8 ) & 0xFF ) ; const db = blue - ( kc & 0xff ) ; let d = ( dr * dr ) + ( dg * dg ) + ( db * db ) ; if ( mind < 0 || d < mind ) { mind = d ; c = kc ; } } return c ; } }