tinygo.org/x/drivers@v0.27.1-0.20240509133757-7dbca2a54349/examples/apds9960/color/main.go (about) 1 package main 2 3 import ( 4 "machine" 5 "time" 6 7 "tinygo.org/x/drivers/apds9960" 8 ) 9 10 func main() { 11 12 // use Nano 33 BLE Sense's internal I2C bus 13 machine.I2C1.Configure(machine.I2CConfig{ 14 SCL: machine.SCL1_PIN, 15 SDA: machine.SDA1_PIN, 16 Frequency: machine.TWI_FREQ_400KHZ, 17 }) 18 19 sensor := apds9960.New(machine.I2C1) 20 21 sensor.Configure(apds9960.Configuration{}) // use default settings 22 23 if !sensor.Connected() { 24 println("APDS-9960 not connected!") 25 return 26 } 27 28 sensor.EnableColor() // enable color engine 29 30 for { 31 32 if sensor.ColorAvailable() { 33 r, g, b, c := sensor.ReadColor() 34 println("Red =", r, "\tGreen =", g, "\tBlue =", b, "\tClear =", c) 35 } 36 time.Sleep(time.Millisecond * 100) 37 } 38 39 }