Difference between revisions of "Mixly Block Category - In / Out"

From Microduino Wiki
Jump to: navigation, search
(Analog Write)
 
(6 intermediate revisions by the same user not shown)
Line 9: Line 9:
  
  
Further reading here (section ''Defining Pin Levels: HIGH and LOW''): https://www.arduino.cc/en/Reference/Constants
+
Read more here (section ''Defining Pin Levels: HIGH and LOW''): https://www.arduino.cc/en/Reference/Constants
  
 
=Digital Pin Operations=
 
=Digital Pin Operations=
Line 16: Line 16:
  
  
Further reading here: https://www.arduino.cc/en/Reference/digitalWrite
+
Read more here: https://www.arduino.cc/en/Reference/digitalWrite
  
 
==Digital Read==
 
==Digital Read==
Line 22: Line 22:
  
  
Further reading here: https://www.arduino.cc/en/Reference/digitalRead
+
Read more here: https://www.arduino.cc/en/Reference/digitalRead
  
 
=Analog Pin Operations=
 
=Analog Pin Operations=
Line 32: Line 32:
  
  
Further reading here: https://www.arduino.cc/en/Reference/analogWrite
+
Read more here: https://www.arduino.cc/en/Reference/analogWrite
  
 
==Analog Read==
 
==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.
 
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
+
 
 +
Read more here: https://www.arduino.cc/en/Reference/analogRead
  
 
=Interrupts=
 
=Interrupts=
Line 48: Line 49:
 
A interrupt service routine (ISR) which is basically a function or subroutine is immediately called once an interrupt has been triggered.  
 
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
+
Read more here (section ''Using Interrupts''): https://www.arduino.cc/en/Reference/AttachInterrupt
 
==Attach Interrupt==
 
==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 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''').  
Line 56: Line 57:
 
NOTE: millis() and microSeconds() will not work within an interrupt.
 
NOTE: millis() and microSeconds() will not work within an interrupt.
  
Further reading here: https://www.arduino.cc/en/Reference/AttachInterrupt
+
 
 +
Read more here: https://www.arduino.cc/en/Reference/AttachInterrupt
 +
 
 
==Detach Interrupt==
 
==Detach Interrupt==
 
Turns off / disables the given interrupt.
 
Turns off / disables the given interrupt.
  
Further reading here: https://www.arduino.cc/en/Reference/DetachInterrupt
+
 
 +
 
 +
Read more here: https://www.arduino.cc/en/Reference/DetachInterrupt
  
 
=Pulse In=
 
=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.
  
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
 
Read more here: https://www.arduino.cc/en/Reference/pulseIn
Line 70: Line 75:
 
=Shift Out=
 
=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.
 
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
 
Read more here: https://www.arduino.cc/en/Reference/shiftOut

Latest revision as of 23:17, 15 February 2017

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.


Read more 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.


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

Digital Read

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


Read more 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.


Read more 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.


Read more 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.

Read more 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.


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

Detach Interrupt

Turns off / disables the given interrupt.


Read more 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