Mixly Block Category - Control

From Microduino Wiki
Jump to: navigation, search

Setup

Blocks are called that are contained within the Setup blocks at the start of the device. The setup function will only run once, after each powerup or reset. It is the very start of the program running and used to initialize variables, pin modes, start using libraries, etc.


Read more here: https://www.arduino.cc/en/Reference/Setup

Delay

Pauses the program for the amount of time in milliseconds (ms) or microseconds (μs) specified.


Read more here: https://www.arduino.cc/en/Reference/Delay

If... else if... else

if, which is used in conjunction with a comparison operator, tests whether a certain condition has been reached, such as an input being above a certain number.

Else If and Else extensions can be added to the blocks by clicking on the gear icon and dragging Else If and Else over. This extends the block.

  • If is the first condition that is checked. If it evaluates to true. Then the contents of the If are executed. In addition, any Else If or Else extensions are skipped. When false, it either either goes to Else If, Else or to the next block. This is dependent on how the block is configured.
  • Else If is checked after If or Else If (above the current one) have been false. When this Else If is true, then the contents are executed. In addition, any Else If or Else extensions are skipped after this one. When false, it either goes to Else If, Else or to the next block. This is dependent on how the block is configured.
  • Else is checked after If or the last Else If have been all false. Contents of Else will be executed.

If

The 'if block checks for a condition is true. It will execute the contained blocks if the condition is true. It will skip the contained blocks if the condition is false.

If... Else if

else if checks for a condition is true, but occurs after the if. Multiple else if can be used and the checks occurs sequentially. Contained blocks execute if the condition is true. Contains blocks will skips if the condition is false.

Else

Blocks within the else occurs when the if and else if are never triggered.


Read more here: https://www.arduino.cc/en/Reference/If , https://www.arduino.cc/en/Reference/Else

Switch

Like if statements, switch...case controls the flow of programs by allowing programmers to specify different code that should be executed in various conditions. In particular, a switch statement compares the value of a variable to the values specified in case statements. When a case statement is found whose value matches that of the variable, the code in that case statement is run.

Adding cases and default can be done with the gear icon on the block. The switch variable is what is tested. It can be attached next to the switch word.

Case

Cases are added by using the gear icon and dragging into the switch block.

Case value will be tested against the switch variable value.

If equal, then the contents of that particular case are ran.

If not equal, then the contents of that case are not ran.

The next case will be tested regardless if this case was executed or not. A break within the case contents will stop case checking.

Default

The Default 's contents (blocks of code) are executed without any value checking (case value and switch variable value). The contents of Default are executed unless a break is triggered in a previous case.


Read more here: https://www.arduino.cc/en/Reference/SwitchCase

Count Loop

The count statement is used to repeat a set of blocks enclosed. An increment counter is usually used to increment and terminate the loop. The count statement is useful for any repetitive operation, and is often used in combination with arrays to operate on collections of data/pins.

There are three parts to the count loop:

  • i - This is the variable name that will be incremented or decremented.
  • Lower bound - The starting value of i
  • Upper bound - The ending value of i
  • Increment value - The value to add for each loop to i

1. The loop first checks if it meets the conditions (if i is within the lower and upper bound values) to execute the set of blocks enclosed. If true, then they will be executed. If fail the loop ends.

2. Once 1 loop cycle has occurred the i is incremented by the 'Increment value, then repeats to step 1.


Read more here: https://www.arduino.cc/en/Reference/For

Repeat Loop

repeat loops will loop continuously, and infinitely, until the expression or variable becomes false. Something must change the tested variable, or the repeat loop will never exit. This could be in your code, such as an incremented variable, or an external condition, such as testing a sensor.


Read more here: https://www.arduino.cc/en/Reference/While

Break

break out is used for breaking out of loops. Useful for if, switch, count and repeat.


Read more here: https://www.arduino.cc/en/Reference/Break

Continue

The continue statement skips the rest of the current iteration of a loop (count, or repeat). It continues by checking the conditional expression of the loop, and proceeding with any subsequent iterations.


Read more here: https://www.arduino.cc/en/Reference/Continue

System Uptime

millis

Returns the number of milliseconds since the board began running the current program.


Read more here: https://www.arduino.cc/en/Reference/Millis

micros

Returns the number of microseconds since the board began running the current program.


Read more here: https://www.arduino.cc/en/Reference/Micros

MsTimer2

MsTimer2 allows blocks of code to run at a certain interval (in ms) as configured. The resolution of the timer is 1ms.

Configuration

Setup the interval in which the timer will trigger every X milliseconds. Blocks contained within MSTimer2 will run at every X milliseconds.

Start

Starts the timer.

Stop

Stops the timer.


Read more here: http://playground.arduino.cc/Main/MsTimer2