Mix.install([
{:kino, "~> 0.6.1"},
{:kino_vega_lite, "~> 0.1.1"}
])
alias VegaLite, as: Vl
Circuits.I2C.detect_devices()
{:ok, bmp} = BMP280.start_link(bus_name: "i2c-1", bus_address: 0x77)
widget =
Vl.new(width: 400, height: 400)
|> Vl.mark(:line)
|> Vl.encode_field(:x, "x", type: :quantitative)
|> Vl.encode_field(:y, "y", type: :quantitative)
|> Kino.VegaLite.new()
|> Kino.render()
Kino.VegaLite.periodically(widget, 200, 0, fn i ->
{:ok, measurement} = BMP280.measure(bmp)
point = %{x: i, y: measurement.temperature_c}
Kino.VegaLite.push(widget, point, window: 500)
{:cont, i + 1}
end)
widget =
VegaLite.new(width: 400, height: 400)
|> VegaLite.mark(:line)
|> VegaLite.encode_field(:x, "X", type: :quantitative)
|> VegaLite.encode_field(:y, "Y", type: :quantitative)
|> Kino.VegaLite.new()
|> Kino.render()
Kino.VegaLite.periodically(widget, 200, 0, fn i ->
{:ok, measurement} = BMP280.measure(bmp)
point = %{x: i, y: measurement.temperature_c}
Kino.VegaLite.push(widget, point, window: 100)
{:cont, i + 1}
end)