Programs a math field
Today we learn how to make the rider's blocks mathematicsfunction. Don't have enough fingers to count? Bitbloq can do the work for you! Let's take a closer look at the math blocks:
- 1 x ZumBloq LED
- 1 x ZumBloq potentiometer
- 1 x ZumBloq Summer
- 1 x ZumBloq button
- 1 x ZumBloq light sensor
- 1 x To the Bloq joystick
- 1 x ZumBloq mini servo
- 1 x ZumBloq LCD
- A ZUM BT 328 control board or one compatible with Arduino UNO
- A USB cable
The block number
This is one of the blocks you will use the most at bitbloq. You can use it to write a numeric number. For example, you can compare its value in the block when ... execute or assign an element directly to a pin or define a time, perform operations, etc. This block has a multitude of possible uses.
Example with the number block
We let the buzzer sound for 300 ms
We used the number block to make the buzzer sound for 300 ms. Internally, the number block is understood as a whole number. This means that it cannot accept any decimal places. Don't forget this as it is important when performing surgery.
The array block
Do you remember how we used this block when programming the joystick? An array (field) is nothing more than a kind of list or a vector that contains three individual variables. As in our case, these can be the X and Y coordinates and the button on our joystick, the hours, minutes and seconds of a clock, etc. When you work with vectors, you have to consider the following. The first element does not correspond to content 1 but to content 0. This means that you have to enter a zero and not a 1 for the first element of a vector. Correspondingly a 1 instead of a 2 if you want to access the second element, etc. The following scheme makes it clearer:
Let's look at an example using the Field block:
Example with the block field
Show the values of the joystick on the LCD display
Here you can see the values X, Y and the value of the joystick on your LCD display. With the block field you can store this information properly and easily retrieve it at any time.
The block random number between ... and ...
This block gives us random values in a predefined interval.Sometimes it can be very useful to have a random value. Why don't you try the game Simon says to create with this block? Or maybe you want your robot to dance or make improvised moves ... There are many options.
The blocks map (convert)
These blocks are used to change the scope of one component and adapt it to another. For example, the potentiometer gives us an integer between 0 and 1023, the mini servo values between 0 and 180 and an LED values between 0 and 255. If we want to use a potentiometer together with a mini servo in such a way that we move when we move of the potentiometer can move the mini servo between 0 and 180 degrees, the block would be to map (convert) ideal for synchronizing both areas. The first block allows us to convert a variable between 0 and 1023 into a range that we want. The second block gives us more freedom, because we can select the range of the input variable as well as the range of the output. Let's see why converting is so handy:
Example with the block map (convert)
Convert the value range of the potentiometer to match the range of the mini servo (0-180 degrees)
In this way we divide the range of the potentiometer, which goes from 0 to 1023, into 180 parts. So for every 6 values of the potentiometer there is one degree of our mini servo. Without this conversion, we would not be able to reasonably control our mini servo with the potentiometer.
This program is identical to this other one that uses the advanced block to convert:
Operator blocks +, -, X, /, ^
You can use these blocks to perform simple math operations like adding, subtracting, multiplying, dividing, and raising to the power. You can use numbers in the block or perform operations with variables.
Example with the operator blocks
We use the add operator to turn on an LED when the sum of the value of the light sensor and the number 20 is less than 100.
Other math operators
There is another block with which we can perform operations like the square root of a number, the natural or tens logarithm, etc. Let's look at an example:
Example with other blocks for math operations
We create a program that outputs the logarithm of a variable. In some programs it can be useful to perform a mathematical operation to modify certain data. For example, if we want our program to calculate the logarithm of the value of a variable.
This is how we get the logarithm of ten of the respective value of the potentiometer.
The rest of the block of ...
Do you remember how to divide in writing? You will remember that often there was a remainder left that you had to divide again to get a number with decimal places. This block outputs the remainder of a division. But what could I need the rest of a division for? Take a look at the following example:
Example with the block remainder of ...
We create a program that outputs the remainder of the division of a random number by 2 when we press the button. If it's an even number (the remainder is zero) the LED will turn on. If it's an odd number (the remainder is 1) the buzzer will sound.
You can find out if a number is even or odd by dividing it by 2. If the number results in a remainder zero when divided by 2, it is an even number. On the other hand, if the remainder is one, the number is odd. As you can see, we also used the random block to create a series of random numbers between 0 and 2000.
These are the math blocks. Some of them may not seem particularly useful to you, or you may not be able to imagine performing such complicated operations. However, the more you become an expert and can program like a true master, the more you will wish that there are many more of them ... I guarantee you that!
Tags: bitbloq, low difficulty
- Why is Aguero underestimated in world football
- How does weathering and erosion work
- Will computers ever be faster than humans?
- Which social listening solutions would you recommend
- Who is the Most Influential Presocratic Philosopher
- Which Disney character is the most attractive
- Owns Pepsi Burger King
- How do you recognize the evil
- How do I travel to Dubai
- Who Offers Inexpensive WordPress Hosting
- When are you going to marry someone
- Where can I buy pokeball headphones
- Is paradise a state of mind
- The truth always comes out
- Who provides taxi service in Frankston
- Where can you learn Sanskrit online
- What is team spirit
- What are the positive qualities of conservatives
- Does a television screen only emit photons
- California has its own unique culture
- Is freeform on DirecTV
- What is Frodo Baggins famous for?
- What is the opposite of optimism
- What is Thursday named after?