Mixly Block Category - In / Out

From Microduino Wiki
Revision as of 23:11, 15 February 2017 by Sonny (talk) (Analog Read)
Jump to: navigation, search

Digital Pin State

When reading or writing to a digital pin there are only two possible values a pin can take/be-set-to: HIGH and LOW.

HIGH

  • A pin is read as HIGH if the voltage on that pin is greater than a certain voltage value (3.0V or 2.0V).
  • A pin is set to the maximum operating voltage (5V or 3.3V) when HIGH is written.

LOW

  • A pin is read as LOW if the voltage on that pin is less than a certain voltage value (1.5V or 1.0V).
  • A pin is set to the minimum voltage (0V) when LOW is written.


Further reading here (section Defining Pin Levels: HIGH and LOW): https://www.arduino.cc/en/Reference/Constants

Digital Pin Operations

Digital Write

Write a HIGH or a LOW value to a digital pin.


Further reading here: https://www.arduino.cc/en/Reference/digitalWrite

Digital Read

Reads the value from a specified digital pin, either HIGH or LOW.


Further reading here: https://www.arduino.cc/en/Reference/digitalRead

Analog Pin Operations

NOTE: Not all pins are capable of analog mode. Analog pins are denoted with the prefix A. i.e. A0, A1, A2 are analog pins.

Analog Write

Writes an analog value (PWM wave) to a pin. Can be used to light a LED at varying brightnesses or drive a motor at various speeds. After a call to analog write the pin will generate a steady square wave of the specified duty cycle until the next call to analog write (or a call to digital read or digital write on the same pin).

The value X between 0 and 255 will output the (X/255) * Maximum Voltage (5V/3.3V) on the pin.


Further reading here: https://www.arduino.cc/en/Reference/analogWrite

Analog Read

Reads the value from the specified analog pin. Returns a value between 0 and 1023. The return value is a map of input voltage (0V to 5V/3.3V) to a value between 0 and 1023.


Further reading here: https://www.arduino.cc/en/Reference/analogRead

Interrupts

Interrupts are useful for making things happen automatically in microcontroller programs, and can help solve timing problems. Good tasks for using an interrupt may include reading a rotary encoder, or monitoring user input.

Interrupts are triggered on a pin when the state of the pin does the following:

  • HIGH to LOW (considered FALLING)
  • LOW to HIGH (considered RISING)
  • CHANGE if the pin changes states (either of the above two).

A interrupt service routine (ISR) which is basically a function or subroutine is immediately called once an interrupt has been triggered.

Further reading here (section Using Interrupts): https://www.arduino.cc/en/Reference/AttachInterrupt

Attach Interrupt

The first parameter to attachInterrupt is an interrupt number. This is the triggering pin. The mode defines the type of trigger. Either (FALLING, RISING, or CHANGE).

The contents / blocks within the attachInterrupt block will be executed when the interrupt triggers.

NOTE: millis() and microSeconds() will not work within an interrupt.

Further reading here: https://www.arduino.cc/en/Reference/AttachInterrupt

Detach Interrupt

Turns off / disables the given interrupt.

Further reading here: https://www.arduino.cc/en/Reference/DetachInterrupt

Pulse In

Reads a pulse (either HIGH or LOW) on a pin. For example, if value is HIGH, pulse in waits for the pin to go HIGH, starts timing, then waits for the pin to go LOW and stops timing. Returns the length of the pulse in microseconds or 0 if no complete pulse was received within the timeout.

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

Shift Out

Shifts out a byte of data one bit at a time. Starts from either the most (i.e. the leftmost) or least (rightmost) significant bit. Each bit is written in turn to a data pin, after which a clock pin is pulsed (taken high, then low) to indicate that the bit is available.

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