This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
docs:blox:examples-logic [2024/08/19 19:30] admin |
docs:blox:examples-logic [2024/08/19 20:45] (current) admin |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== 6.1 BLOX: Logic and Events ====== | + | ====== 6.2 BLOX: Events |
| Using BLOX to build firmware is like piecing together a puzzle where each piece represents a different action or decision your device needs to make. Here’s a simple way to understand it: | Using BLOX to build firmware is like piecing together a puzzle where each piece represents a different action or decision your device needs to make. Here’s a simple way to understand it: | ||
| - | **Everything Happens Sequentially**: | + | ===== 6.2.1 Everything Happens Sequentially |
| * Imagine you're giving instructions to a robot. You tell it to move forward, then turn left, then pick up an object. The robot will follow these steps one after another, in the exact order you gave them. | * Imagine you're giving instructions to a robot. You tell it to move forward, then turn left, then pick up an object. The robot will follow these steps one after another, in the exact order you gave them. | ||
| * In BLOX, each block you place in the workspace is like an instruction for your device, and it will follow these steps in the order they appear. | * In BLOX, each block you place in the workspace is like an instruction for your device, and it will follow these steps in the order they appear. | ||
| - | **Logic Flow Control**: | + | ===== 6.2.2 Logic Flow Control |
| * Inside this sequence, you may sometimes want your robot to repeat a task, like picking up 10 objects one by one. Instead of giving the same instruction 10 times, you can use a Repeat Block. | * Inside this sequence, you may sometimes want your robot to repeat a task, like picking up 10 objects one by one. Instead of giving the same instruction 10 times, you can use a Repeat Block. | ||
| * A " | * A " | ||
| * Sometimes, you want your robot to make decisions. For example, "If there' | * Sometimes, you want your robot to make decisions. For example, "If there' | ||
| - | * In Blockly, you can use logic blocks like " | + | * In BLOX, you can use logic blocks like " |
| - | * If you'd like the device | + | * If you'd like the device |
| * There are many more examples | * There are many more examples | ||
| - | By arranging these blocks in the workspace, you're essentially building a set of instructions that the firmware will follow, making your device do exactly what you want it to do. \\ \\ **To demonstrate this, lets start with a very basic example.** | + | By arranging these blocks in the workspace, you're essentially building a set of instructions that the firmware will follow, making your device do exactly what you want it to do. |
| + | |||
| + | ===== 6.2.3 Sequential Instructions ===== | ||
| + | |||
| + | **Let' | ||
| + | |||
| + | Your BLOX has two onboard RGB LEDs. Let's setup a simple program to control these LEDs. No inputs, no change to the flow of the program. Just a set of instructions executed sequentially. | ||
| + | |||
| + | ^ Once it starts to run the firmware we want to: ^ If we build this out in BLOX it would look like this: | | ||
| + | | \\ - Set both LEDs to RED \\ - Wait for 1 second \\ - Set both LEDs to GREEN \\ - wait for 1 second \\ - Set both LEDs to BLUE \\ - wait for 1 second \\ - Then repeat (the pattern will run over and over)| | ||
| + | |||
| + | It's really that easy! You can substitute the LEDs for any other output and already build out a couple interesting projects | ||
| + | |||
| + | |||
| + | ===== 6.2.4 Control flow of Instructions using a Logic block ===== | ||
| - | Your BLOX has two onboard RGB LEDs. Let' | + | **Let' |
| - | - Set both LEDs to RED | + | Lets add a little logic to the program. Suppose we only want the LED pattern |
| - | - Wait for 1 second | + | |
| - | - Set both LEDs to GREEN | + | |
| - | - wait for 1 second | + | |
| - | - Set both LEDs to BLUE | + | |
| - | - wait for 1 second | + | |
| - | - Then repeat (the pattern will run over and over) | + | |
| - | **If we build this out in BLOX it would look like this:** | + | ^ Once it starts to run the firmware we want to: ^ |
| + | | \\ IF the button is pressed: | ||
| - | {{: | + | You can apply this exact concept to a lot of other examples |
| + | * Waiting for a motion sensor before using the Beeper to make on an alarm sound | ||
| + | * Waiting for a button press before raising a TV lift actuator | ||
| + | * Read the status of a garage door sensor and display the status on an LCD | ||
| + | * Use it as a thermostat, if the temperature drop below a certain value, turn on a heating device | ||