Reads the value from a specified digital pin, either HIGH or LOW.
digitalRead(pin)
pin: the number of the digital pin you want to read (int)
int val = 0; // variable to store the read value void setup() { pinMode(RED_LED, OUTPUT); // sets the red LED as output Serial.begin(9600); } void loop() { P1OUT = ~P1OUT; val = digitalRead(RED_LED); // read the output pin Serial.print(val); }
If the pin isn't connected to anything, digitalRead() can return either HIGH or LOW (and this can change randomly).
The analog input pins can be used as digital pins.
Corrections, suggestions, and new documentation should be posted to the Forum.
The text of the Energia Reference is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Energia reference is based on Arduino reference. Code samples in the reference are released into the public domain.