You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The ML model runs several times a second and calculates a certainty value for each action. The estimated action is the action with the highest certainty. An action cannot be the estimated action when its certainty is below the recognition point. Some programs may need to use the certainty values directly, for example to display or log them. Most programs can use the estimated action instead of certainty values.
10
+
11
+
## Parameters
12
+
13
+
-**event**: one of the actions the machine learning model was trained on.
14
+
15
+
## Returns
16
+
17
+
- a percentage as a [number](/types/number) from 0 to 100, representing the ML model’s certainty that this is the action being performed. The certainty for `unknown` is always 0.
18
+
19
+
## Example
20
+
21
+
This example displays the ML model's certainty, in percent, that the current action is `clapping` every second.
The ML model updates its estimated action several times a second. This function returns `true` if the chosen action is currently estimated. Use the boolean value to make logical decisions in your program.
10
+
11
+
Some programs will be easier to write using the “on ML start” and “on ML stop” event handlers instead.
12
+
13
+
## Parameters
14
+
15
+
-**event**: one of the actions the machine learning model was trained on. The special value `unknown` represents the case where no action has a certainty above the recognition point.
16
+
17
+
## Returns
18
+
19
+
- a [boolean](/types/boolean) value that is `true` if the ML action is the estimated action, `false` if the ML action is not the estimated action.
20
+
21
+
## Example
22
+
23
+
This example will show a tick icon on the LED display if the estimated action is `clapping` at the time the conditional statement is checked.
Start an [event handler](/reference/event-handler) (part of the program that will run when something happens). This handler works when the ML model’s estimated action changes to the action you select.
4
+
5
+
```sig
6
+
ml.onStart(ml.event.Unknown, function () {
7
+
})
8
+
```
9
+
10
+
The ML model updates its estimated action several times a second, but this event handler only runs when the estimated action changes.
11
+
12
+
## Parameters
13
+
14
+
-**event**: one of the actions the machine learning model was trained on. The special value `unknown` represents the case where no action has a certainty above the recognition point.
15
+
16
+
## Example
17
+
18
+
This example plays a musical melody in the background when the action `clapping` has a certainty above the recognition point.
Start an [event handler](/reference/event-handler) (part of the program that will run when something happens). This handler works when the ML model’s estimated action changes from the action you select.
4
+
5
+
```sig
6
+
ml.onStop(ml.event.Unknown, function () {
7
+
})
8
+
```
9
+
10
+
When an action changes, the stop event handler for the previous action will run, followed by the start event handler for the next action.
11
+
12
+
For example, if your start event handler for an action starts music playing in the background, you could use a stop event handler to stop it.
13
+
14
+
## Parameters
15
+
16
+
-**event**: one of the actions the machine learning model was trained on. The special value `unknown` represents the case where no action has a certainty above the recognition point.
17
+
18
+
## Example
19
+
20
+
This example stops playing a musical melody when the estimated action changes from `clapping` to any other action.
Start an [event handler](/reference/event-handler) (part of the program that will run when something happens). This handler works when the ML model’s estimated action changes from the action you select.
4
+
5
+
```sig
6
+
ml.onStopDetailed(ml.event.Unknown, function (duration) {
7
+
})
8
+
```
9
+
10
+
When an action changes, the stop event handler for the previous action will run, followed by the start event handler for the next action.
11
+
12
+
For example, if your start event handler for an action starts music playing in the background, you could use a stop event handler to stop it.
13
+
14
+
The event handler is passed a `duration` parameter. The duration is the [number](/types/number) of milliseconds since this action became the estimated action. You can use the duration parameter in your code, for example displaying it or using a variable to keep a running total.
15
+
16
+
## Parameters
17
+
18
+
-**event**: one of the actions the machine learning model was trained on. The special value `unknown` represents the case where no action has a certainty above the recognition point.
19
+
20
+
## Example
21
+
22
+
This example shows on the LED display, in seconds, how long the estimated action was `clapping`, when the estimated action changes from `clapping` to any other action.
23
+
24
+
```blocks
25
+
ml.onStopDetailed(ml.event.Clapping, function (duration) {
0 commit comments