Condition Based Logic based on Sensor Values
Last updated
Was this helpful?
Last updated
Was this helpful?
Scratch uses visual blocks or "Scratch blocks" to represent different commands and actions. These blocks can be dragged and dropped onto a workspace to create programs or scripts. Scratch blocks come in different colors and shapes, and each block represents a specific action or command that can be used to create interactive stories, games, and animations.
One of the features of Scratch that makes it easy to use for beginners is the use of loops and conditionals. Loops are blocks that allow you to repeat a certain set of actions multiple times. For example, you can use a "repeat" loop to make a sprite move back and forth across the screen multiple times. The loop will continue to run until a certain condition is met, such as a specific number of times or until a certain amount of time has passed.
Conditionals, on the other hand, are blocks that allow you to create different paths or outcomes based on a certain condition. For example, you can use an "if-else" block to create a program that reacts differently depending on the user's input. If the user clicks on a certain button, the program will do one thing, and if they click on a different button, the program will do something else.
In Scratch, loops and conditionals are represented by specific blocks that you can drag and drop onto your workspace. By combining these blocks with other Scratch blocks, you can create complex programs that can respond to user input, interact with other objects on the screen, and perform a variety of actions.
Overall, Scratch blocks are a powerful tool that can be used to create a wide range of projects and programs. By exploring the different types of blocks and experimenting with different combinations, you can gain a better understanding of how programming works and how you can use it to bring your ideas to life.
Loops are available under the controls section of the interface.
The "looks" blocks in Scratch are a set of programming blocks that allow you to change the appearance of sprites (characters or objects) in your Scratch project. The looks blocks can be found in the "Looks" category in the Scratch block palette.
Some common looks blocks include:
1. The "say" block: This block allows you to make a sprite say something. You can enter the text you want the sprite to say directly into the block, or you can use a variable or other block to generate the text dynamically.
2. The "show" and "hide" blocks: These blocks allow you to show or hide a sprite on the screen. For example, you might use the "hide" block to make a sprite disappear when it reaches a certain point on the screen.
3. The "switch costume" block: This block allows you to change the costume (or appearance) of a sprite. You can add multiple costumes to a sprite and use this block to switch between them.
4. The "change size" block: This block allows you to change the size of a sprite. You can make the sprite larger or smaller by entering a value into the block, or you can use a variable or other block to change the size dynamically.
Overall, the looks blocks in Scratch give you a lot of control over the appearance of your sprites, which can help you create engaging and visually appealing projects.
In this example we leverage an if/else loop to monitor the value of the MODI sensor, followed by using a say block to write a message to the page when conditions are met.
The goal of this exercise is to write βGoβ to the screen when the sensor is below a certain threshold, and βStopβ when the value is above it. The full code is illustrated below.