Skip to main content

Input/Output

Fundamental concepts

Digital vs analogue signals

In electronics, a signal is a voltage or current that conveys information. Signals can be either digital or analogue.

  • Digital signals can only have specific, distinct (discrete) values.
  • Analogue signals can have any value within a continuous range.

Digital pins

Digital pins have two possible states: HIGH (on) or LOW (off). Just like a light switch can only be on or off, a digital pin can only be in one of these two states at any given time.

Each pin can be used as an input or an output.

  • Input: Read the state of the pin (HIGH or LOW).
  • Output: Set the state of the pin (HIGH or LOW).

Examples

  • A digital temperature sensor might send a HIGH signal when the temperature exceeds a certain threshold, and a LOW signal when it's below that threshold.
  • An LED set as an output can be turned on (HIGH state) or off (LOW state) by setting the pin's state accordingly.
  • A motion sensor set as an input might send a HIGH signal when it detects movement, and a LOW signal when it doesn't.

Analogue pins

Analogue pins can have a range of values between 0 and 1023. These pins are used to read values from sensors that provide a range of data, such as light sensors, potentiometers, and temperature sensors.

Examples

  • A potentiometer connected to an analogue pin can send a value from 0 (fully anti-clockwise) and 1023 (fully clockwise), with many possible values in between.
  • A light sensor can send values from 0 (dark) to 1023 (bright), depending on the amount of light it detects.
info

Not all pins on a microcontroller can read analogue values. The number and placement of analogue pins vary depending on the board.

Set pin state

The set pin state block sets a digital pin to a HIGH (on) or LOW (off) state. It takes two inputs:

  • Pin number: The specific pin you want to control.
  • State: HIGH or LOW.

The dropdown menu for the pin number will show all available digital pins for the selected board.

Set PWM pin state

The set PWM pin state block sets a PWM (Pulse Width Modulation) pin to a specific value between 0 and 255.

  • Pin number: The specific pin you want to control.
  • Value: The value you want to set the pin to (between 0 and 255).

PWM is useful for controlling the brightness of LEDs, the speed of motors, and other applications where you need to vary the intensity of a signal.

info

Pulse Width Modulation (PWM) is a technique used to generate analogue-like signals using digital pins. By rapidly turning a pin on and off, you can simulate an analogue signal with varying intensity.

Set pin mode

The pin mode block sets the mode of a specific pin to either INPUT or OUTPUT.

  • Pin number: The specific pin you want to configure.
  • Mode: INPUT or OUTPUT.

When a pin is set to INPUT, it can be used to read the state of a sensor or another device. When set to OUTPUT, it can be used to control an LED, motor, or another device.

Read digital pin state

The read digital pin state block reads the current state (HIGH or LOW) of a digital pin. It takes one input:

  • Pin number: The specific pin you want to read.

This block outputs a boolean (true/false) value, which can be used in conditional blocks to make decisions based on the pin's state.

  • HIGH is equivalent to true.
  • LOW is equivalent to false.

Read analogue pin value

The read analogue pin block reads the current analogue value (between 0 and 1023) of an analogue pin. It takes one parameter:

  • Pin number: The specific pin you want to read.

This block outputs the analogue reading as a number, which can be used in calculations or to control other components.

Set state of built-in LED

Most microcontroller boards include a built-in LED that can be controlled directly. This block sets the state of the built-in LED to HIGH (on) or LOW (off).

Set analogue reference

The set analogue reference block sets the reference voltage for the analogue pins. The reference voltage determines the maximum value that can be read from an analogue pin. It takes one input, the reference voltage:

  • default: The default reference voltage, which is usually the board's operating voltage (e.g., 5V).
  • internal: The internal reference voltage of the microcontroller.
  • internal 1.1V: Internal reference voltage of 1.1V.
  • internal 2.56V: Internal reference voltage of 2.56V.
  • external: An external reference voltage connected to the AREF pin.
warning

Only change the analogue reference if you know what you're doing. Using the wrong reference voltage can damage your board or produce incorrect readings.

Tone on pin

This block generates a square wave tone on a specified pin. It takes three parameters:

  • Pin number: The specific pin you want to use.
  • Frequency: The frequency of the tone in Hertz (Hz).
  • Duration: The duration of the tone in milliseconds (ms).
info

Hertz (Hz) is a unit of frequency that represents the number of cycles per second. A higher frequency produces a higher-pitched tone, while a lower frequency produces a lower-pitched tone.

Stop tone on pin

This block stops the tone generated by the tone on pin block on the specified pin.

Duration of pulse on pin

This block measures how long a pulse on a pin lasts (in microseconds). It takes three parameters:

  • Pin number: The specific pin you want to monitor.
  • State: The state to measure the pulse duration for (HIGH or LOW).
  • Timeout: The maximum duration to wait for the pulse in milliseconds (ms).

Duration of long pulse on pin

This block measures how long a pulse on a pin lasts (in milliseconds). It takes three parameters:

  • Pin number: The specific pin you want to monitor.
  • State: The state to measure the pulse duration for (HIGH or LOW).
  • Timeout: The maximum duration to wait for the pulse in milliseconds (ms).

Shift incoming byte

Shifts an incoming byte (8 bits) into a register. This block is useful for reading data from serial communication, such as UART or SPI.

  • Data pin: The pin to read the incoming byte from.
  • Clock pin: The pin to use as the clock signal for shifting the bits.
  • Bit order: The order in which the bits are shifted (LSB first or MSB first).
info
  • Least Significant Bit (LSB) is the bit position that represents the smallest value in binary (e.g., 00000001).
  • Most Significant Bit (MSB) is the bit position that represents the largest value in binary (e.g., 10000000).