tinygo.org/x/drivers@v0.27.1-0.20240509133757-7dbca2a54349/examples/veml6070/main.go (about) 1 package main 2 3 import ( 4 "time" 5 6 "machine" 7 8 "tinygo.org/x/drivers/veml6070" 9 ) 10 11 func main() { 12 machine.I2C0.Configure(machine.I2CConfig{}) 13 sensor := veml6070.New(machine.I2C0) 14 15 if !sensor.Configure() { 16 println("VEML6070 could not be configured") 17 return 18 } 19 20 println("VEML6070 configured") 21 22 for { 23 intensity, _ := sensor.ReadUVALightIntensity() 24 println("UVA light intensity:", float32(intensity)/1000.0, "W/(m*m)") 25 26 switch sensor.GetEstimatedRiskLevel(intensity) { 27 case veml6070.UVI_RISK_LOW: 28 println("UV risk level: low") 29 case veml6070.UVI_RISK_MODERATE: 30 println("UV risk level: moderate") 31 case veml6070.UVI_RISK_HIGH: 32 println("UV risk level: high") 33 case veml6070.UVI_RISK_VERY_HIGH: 34 println("UV risk level: very high") 35 case veml6070.UVI_RISK_EXTREME: 36 println("UV risk level: extreme") 37 } 38 39 time.Sleep(2 * time.Second) 40 } 41 }