Sunday, June 20, 2010

Arduino learning-6

pinMode(pin, mode)
Used in void setup() to configure a specified pin to behave either as an INPUT or an OUTPUT.
pinMode(pin, OUTPUT); // sets ‘pin’ to output
Arduino digital pins default to inputs, so they don't need to be explicitly declared as inputs with pinMode(). Pins configured as INPUT are said to be in a high-impedance state.
There are also convenient 20KΩ pullup resistors built into the Atmega chip that can be accessed from software. These built-in pullup resistors are accessed in the following manner:
pinMode(pin, INPUT); // set ‘pin’ to input
digitalWrite(pin, HIGH); // turn on pullup resistors
Pullup resistors would normally be used for connecting inputs like switches. Notice in the above example it does not convert pin to an output, it is merely a method for activating the internal pull-ups.
Pins configured as OUTPUT are said to be in a low-impedance state and can provide 40 mA (milliamps) of current to other devices/circuits. This is enough current to brightly light up an LED (don't forget the series resistor), but not enough current to run most relays, solenoids, or motors.
Short circuits on Arduino pins and excessive current can damage or destroy the output pin, or damage the entire Atmega chip. It is often a good idea to connect an OUTPUT pin to an external device in series with a 470Ω or 1KΩ resistor.

Reads the value from a specified digital pin with the result either HIGH or LOW. The pin can be specified as either a variable or constant (0-13).
value = digitalRead(Pin); // sets 'value' equal to
// the input pin
digitalWrite(pin, value)
Outputs either logic level HIGH or LOW at (turns on or off) a specified digital pin. The pin can be specified as either a variable or constant (0-13).
digitalWrite(pin, HIGH); // sets 'pin' to high
The following example reads a pushbutton connected to a digital input and turns on an LED connected to a digital output when the button has been pressed:
int led = 13; // connect LED to pin 13
int pin = 7; // connect pushbutton to pin 7
int value = 0; // variable to store the read value
void setup()
pinMode(led, OUTPUT); // sets pin 13 as output
pinMode(pin, INPUT); // sets pin 7 as input
void loop()
value = digitalRead(pin); // sets 'value' equal to
// the input pin
digitalWrite(led, value); // sets 'led' to the
} // button's value
22 |
Related Posts Plugin for WordPress, Blogger...
Disclaimer: All the information in this blog is just gathered from different sites in the web and placed here and I am not the owner for these content

Popular Projects


My Blog List

Give Support

Give Support
Encourage me Through Comments & by Following