Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/ / Hardware: Two buttons with GPIO pullup resistors. / / The LCD. / / / / / / Problem Statement: Build an Arduino project

// Hardware: Two buttons with GPIO pullup resistors.
// The LCD.
//
//
// Problem Statement: Build an Arduino project that uses two buttons and the LCD. One button will
// clear the LCD and re-initialize counter variable to zero. If button == pushed, clear LCD // and counter =0.
// The second button will enter a while loop and increment the counter variable by one
// and display value on LCD. While button == pushed, counter = counter +1 and write counter
// value to display.
// Note: 16-bit integer range of -32,768 to 32,767. Then rolls over to zero.
//
//**** Pseudocode Algorithm ****
//
// create a global integer variable counter and initialize to zero
//
// setup()
//
// set pin 4 as input for button one with a pullup resistor
// set pin 5 as input for button two with a pullup resistor
// setup pins for LCD use Lab-4 as your guide
//
//
// loop()
//
// if ( button one pushed )
//
// clear LCD // command from Lab-4
//
// counter =0
//
//
// while( button two pushed )
//
// counter = counter +1
//
// write counter value to LCD // commands from Lab-4
//
// end while loop
//
//
// end loop
Question: What is smallest value you can get for count variable shortest time pushed button two ?
____________________.
Question: What is highest value you can get for count variable longest time push button two ?
____________________.
Question: Change program so the counter variable subtracts one, instead of adds one. What is smallest (negative) value you can get for count variable longest time button two pushed ?
____________________.
CHEGG'S CODE ANSWER PROVIDED IS AS FOLLOWS:
Based on the provided pseudocode algorithm, let's translate it into an Arduino sketch:
#include
// Define LCD pins
LiquidCrystal lcd(12,11,5,4,3,2);
// Global counter variable
int counter =0;
void setup(){
// Set up LCD
lcd.begin(16,2);
// Set up button pins with pull-up resistors
pinMode(4, INPUT_PULLUP); // Button 1
pinMode(5, INPUT_PULLUP); // Button 2
}
void loop(){
// Check if button one is pushed
if (digitalRead(4)== LOW){
// Clear LCD and reset counter
lcd.clear();
counter =0;
}
// Check if button two is pushed
while (digitalRead(5)== LOW){
// Increment counter
counter++;
// Write counter value to LCD
lcd.setCursor(0,1);
lcd.print("Counter: "+ String(counter));
delay(500); // Add a delay to avoid rapid counting due to button bouncing
}
}
Explanation:
The LiquidCrystal library is used for interfacing with the LCD.
In the setup function, pins for buttons and LCD are initialized.
The loop function continuously checks the state of buttons.
If button one is pushed, it clears the LCD and resets the counter to zero.
If button two is pushed, it enters a while loop, incrementing the counter and displaying it on the LCD until the button is released.
A delay of 500 milliseconds is included to avoid rapid counting due to button bouncing.
THE BREADBOARD AND CIRCUIT HAS BEEN WIRED CORRECTLY. THIS IS WHAT IS HAPPENING: THE BUTTON CONNECTED TO PIN 5 IS RESETTING AND CLEARING THE LCD (IT SHOULD BE PIN 4 PER THE CODE). THE BUTTON CONNECTED TO PIN 4 DOES NOTHING AS OF NOW. ALSO, THE LCD BEGINS COUNTING CONTINUOUSLY (BY 1) AS SOON AS THE CODE IS UPLOADED TO THE BOARD. PRESSING PIN 5 RESETS THE LCD BACK TO ZERO, THEN THE LCD AGAIN BEGINS AUTOMATICALLY COUNTING UP BY 1 ON ITS OWN WITH NO BUTTON INITIATING THE COUNTING. THANK YOU!
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Identify and control your anxieties

Answered: 1 week ago

Question

Understanding and Addressing Anxiety

Answered: 1 week ago