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:49] 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. | 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. | ||
| - | ===== Sequential Instructions ===== | + | ===== 6.2.3 Sequential Instructions ===== |
| **Let' | **Let' | ||
| Line 28: | Line 30: | ||
| | \\ - 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)| | | \\ - 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! | + | It's really that easy! You can substitute the LEDs for any other output and already build out a couple interesting projects |
| - | ===== Control flow of Instructions using an IF block ===== | + | ===== 6.2.4 Control flow of Instructions using a Logic block ===== |
| **Let' | **Let' | ||
| Line 44: | Line 46: | ||
| * Waiting for a button press before raising a TV lift actuator | * 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 | * 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 | ||