tinygo.org/x/drivers@v0.27.1-0.20240509133757-7dbca2a54349/examples/amg88xx/main.go (about)

     1  package main
     2  
     3  import (
     4  	"image/color"
     5  	"machine"
     6  
     7  	"tinygo.org/x/drivers/st7735"
     8  
     9  	"tinygo.org/x/drivers/amg88xx"
    10  )
    11  
    12  func main() {
    13  
    14  	machine.SPI1.Configure(machine.SPIConfig{
    15  		SCK:       machine.SPI1_SCK_PIN,
    16  		SDO:       machine.SPI1_SDO_PIN,
    17  		SDI:       machine.SPI1_SDI_PIN,
    18  		Frequency: 8000000,
    19  	})
    20  	machine.I2C0.Configure(machine.I2CConfig{SCL: machine.SCL_PIN, SDA: machine.SDA_PIN})
    21  
    22  	display := st7735.New(machine.SPI1, machine.TFT_RST, machine.TFT_DC, machine.TFT_CS, machine.TFT_LITE)
    23  	display.Configure(st7735.Config{
    24  		Rotation: st7735.ROTATION_90,
    25  	})
    26  	display.FillScreen(color.RGBA{0, 0, 0, 255})
    27  
    28  	camera := amg88xx.New(machine.I2C0)
    29  	camera.Configure(amg88xx.Config{})
    30  
    31  	var data [64]int16
    32  	var value int16
    33  	for {
    34  		// get the values of the sensor in millicelsius
    35  		camera.ReadPixels(&data)
    36  
    37  		for j := int16(0); j < 8; j++ {
    38  			for i := int16(0); i < 8; i++ {
    39  				value = data[63-(i+j*8)]
    40  				// treat anything below 18°C as 18°C
    41  				if value < 18000 {
    42  					value = 0
    43  				} else {
    44  					value = (value - 18000) / 36
    45  					// our color array only have 433 values, avoid getting a value that doesn't exist
    46  					if value > 432 {
    47  						value = 432
    48  					}
    49  				}
    50  				// show the image on the PyBadge's display
    51  				display.FillRectangle(16+i*16, j*16, 16, 16, colors[value])
    52  			}
    53  		}
    54  	}
    55  
    56  }