The digital pin can be either High or Low. Which can mean in logic Zero or One.
This input can be the state of push button, input voltage in binary form or you may use analog input to Arduino digital inputs as a way of quantization.
In real life you can use it to sense the logic state of a button (ON/OFF Switch or Push Button) to check its position.
You can also use it to sense the presence of voltage as an input to Arduino form another circuit.
Use of relays can be considered as a digital input to Arduino.
digitalRead()
[Digital I/O]Description
Reads the value from a specified digital pin, either
HIGH
or LOW
.Syntax
digitalRead(pin)
Parameters
pin
: the number of the digital pin you want to readReturns
HIGH
or LOW
Example Code
Sets pin 13 to the same value as pin 7, declared as an input.
int ledPin = 13; // LED connected to digital pin 13 int inPin = 7; // pushbutton connected to digital pin 7 int val = 0; // variable to store the read value void setup() { pinMode(ledPin, OUTPUT); // sets the digital pin 13 as output pinMode(inPin, INPUT); // sets the digital pin 7 as input } void loop() { val = digitalRead(inPin); // read the input pin digitalWrite(ledPin, val); // sets the LED to the button's value }
Check our books on Amazon we created on our way to find happiness.A Trip To Siwa Oasis
No comments:
Post a Comment