Question: Below is the Arduino code which is working as assigned. Button 1 is attached to Pin 4 . Button 1 ( Pin 4 ) when
Below is the Arduino code which is working as assigned. Button is attached to Pin Button Pin when pressed is clearing the LCD and resetting the counter to zero. Button is attached to Pin Button Pin when held down is incrementing the LCD counter continuously by it is inside a while loop Within the code, both pin & digital reads are set to HIGH, instead of LOW. This was necessary to achieve the desired output given the wiring and circuit board. However, this appears to be backwards, as the pressing the buttons should pull the input resistor to ground and creating a LOW state. Why would the code work as assigned if the button digital reads are set to HIGH instead of LOW? Thank you, code follows.....
#include
Define LCD pins
LiquidCrystal lcd;
Global counter variable
int counter ;
void setup
Set up LCD
lcd.begin;
lcd.clear;
counter ;
Set up button pins with pullup resistors
pinMode INPUTPULLUP; Button
pinMode INPUTPULLUP; Button
void loop
Check if button one is pushed
while digitalRead HIGH
Clear LCD and reset counter
lcd.clear;
delay;
lcd.setCursor;
lcd.printCounter: ;
counter ;
Check if button two is pushed
while digitalRead HIGH
Increment counter
counter;
Write counter value to LCD
lcd.setCursor;
lcd.printCounter: Stringcounter;
delay; Add a delay to avoid rapid counting due to button bouncing
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
