Skip to main content

Posts

Showing posts from December, 2020

Reading IO Pin Status in Arduino

To read the status of input pins of Arduino board following code can be used: Here internal pull up resistors of the IO pins are enabled to avoid getting random readings from pins when nothing is connected to them. than each required pin is read turn by turn and the status of these pins are saved in a 8 bit register. by accessing this register we can than access the pin status of all input pins. While declaring pinMode of a pin if we used INPUT_PULLUP insted of INPUT than we can eleminate the need external pull down resistor. the code is as follows   void setup() {   Serial.begin(9600);   pinMode(2,INPUT_PULLUP);   pinMode(3,INPUT_PULLUP);   pinMode(4,INPUT_PULLUP);   pinMode(5,INPUT_PULLUP);   pinMode(6,INPUT_PULLUP);   pinMode(7,INPUT_PULLUP);   pinMode(8,INPUT_PULLUP);   pinMode(9,INPUT_PULLUP); } void loop() {   byte inputs = 0;   if(digitalRead(2))inputs +=1;   if(digitalRead(3))inputs +=2;   if(digitalRead(4))inputs +=4;   if(digitalRead(5))inputs +=8;   if(digitalRead(6))inputs