Difference between revisions of "Inputs and Outputs"

From robotics
(Inputs)
(Digital Input)
Line 25: Line 25:
  
 
=== Digital Input ===
 
=== Digital Input ===
 +
 +
Digital Inputs are pins that can detect whether the pin is at VCC (source voltage) or GND. The barrier threshold can vary but it usually lies at about half of VCC. There are two lines of code that are important for using a digital input.
 +
 +
pinMode(pin #,INPUT);
 +
 +
pinMode is a function that sets up a digital pin. The pin number can be any pin that is not in use. The second parameter has 3 options INPUT, OUTPUT, or INPUT_PULLUP.
 +
 +
With standard INPUT the pin will float which means it can change if it is disconnected.
  
 
=== Interrupts ===
 
=== Interrupts ===

Revision as of 15:45, 7 July 2014

Inputs and Outputs (IO)

All programs work on an Input / Output basis, whether it is a PC based program taking in a joystick and outputting the commands to a game character or a microcontroller that flashes an LED when a button is pressed. Arduinos support a number of inputs and outputs.

Inputs

Inputs are essential and vary greatly.

There are several different ways to get an Input with an Arduino.

Analog Input

Digital Input

Interrupts

Analog

Analog Inputs Vary from The voltage source to ground. With most Arduino boards they output a value between 0-1023 linearly proportional to the voltage. Example on a 5V Arduino 0V=0, 2.5v=511, 5V=1023.

int sensorValue = analogRead(pin #); 

This line of code would initialize a variable type int with the name sensorValue and make it equal to the analog signal on the pin


Digital Input

Digital Inputs are pins that can detect whether the pin is at VCC (source voltage) or GND. The barrier threshold can vary but it usually lies at about half of VCC. There are two lines of code that are important for using a digital input.

pinMode(pin #,INPUT);

pinMode is a function that sets up a digital pin. The pin number can be any pin that is not in use. The second parameter has 3 options INPUT, OUTPUT, or INPUT_PULLUP.

With standard INPUT the pin will float which means it can change if it is disconnected.

Interrupts