This code works on CPX. It uses the graph block to plot temperature Centigrade to the onboard neopixels.
You have to define the the maximum value of the variable, np in the graph block. In my previous attempt I did not do that!
This code works on CPX using Microsoft Makecode or Maker Makecode. It does not work on a CPB using Maker Makecode.
Code: Select all
let np = 0
let T = 0
let Tmin = 20
let Tmax = 30
forever(function () {
T = input.temperature(TemperatureUnit.Celsius)
np = Math.map(T, Tmin, Tmax, 0, light.onboardStrip().length() - 1)
light.graph(np, light.onboardStrip().length() - 1)
console.log(np)
pause(100)
})