Skip to main content

How to resize widgets with sensors

In this tutorial we will use an M5 stack fire with a light sensor unit attached to port B.

Sensor configuration

{
{
"m5devices": [
{
"uid": "M5",
"sensors": [
{
"id": "light",
"type": "lightSensor",
"events": {
"onDark": {
"event": "dark"
},
"onBright": {
"event": "bright"
}
},
"settings": {
"log": false,
"pin": 36,
"ranges": {
"onDark": {
"max": 4096,
"min": 3000
},
"onBright": {
"max": 2919,
"min": 0
}
}
}
}
]
}
]
}
SHOW CONSOLE WINDOW

After you sat the configuration, enable the Show console window on your device, when you interact with the board it will show the actual sensor's ID, Event and Value, which will be needed in content creation.

Content

Firstly, we need to create a mock datasource with our image parameters. (width, height, top, left, etc...)

  • Navigate yourself to Properties >> Content >> base data path then select create mock datasource

In the mock datasource you need to give the data in JSON format.

img.png
  • Put down the widget you wish to resize, then select Bind anything in Properties >> Widget >> Other tab.
  • Bind the Positions from the datasource
img.png

Example binding data:

img.png
  • If you are done with these steps, you can configure the sensor events.

  • Here we will listen to some events like "bright" and "dark".

  • With the Change datasource action type we will change the documents mock datasource with overwrite property action, where we want to change our mock datasource data like height, width..etc.

  • Create an action batch for the event dark

  • Click on the actions then add Change datasource action, select the mock datasource you created before and add the property name and the value like this:

img.pngimg.png
  • Create an action batch for event bright then repeat the previous steps:
img_1.pngimg.png

After you created all the actions, save it, save the content, then try it out

Downloadable content