Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help in filling the missing lines in the program template provided down below. (Arduino Uno). Using the program template provided, fill in the missing

Need help in filling the missing lines in the program template provided down below. (Arduino Uno).

  1. Using the program template provided, fill in the missing lines in the program which increments an unsigned integer variable when the pin 2 button is pressed and decrements an unsigned integer variable when the pin 3 button is pressed. Your program must display the integer variable (modulo 8) on the 7-segment LED display you designed in the previous lab. Once again you should be able to reuse parts of lab 2. (3 points)

Program Template:

// Breadboard using the same pins as used in the code

int incrButtonPin = 6; // Increment Button Pin

int decrButtonPin = 5; // Decrement Button Pin

int counter = 0; //Keeps track of the current digital value

boolean IncButtonLast = LOW;

boolean IncButtonCurrent = LOW;

boolean DecButtonLast = LOW;

boolean DecButtonCurrent = LOW;

void setup() { // Increment and decrement pins

pinMode(incrButtonPin, INPUT);

pinMode(decrButtonPin, INPUT); // pins used for 7-segment Display

pinMode(7, OUTPUT);

pinMode(8, OUTPUT);

pinMode(9, OUTPUT);

pinMode(10, OUTPUT);

pinMode(11, OUTPUT);

pinMode(12, OUTPUT);

pinMode(13, OUTPUT);

// pins used for input to the DAC R2R Ladder

pinMode(2, OUTPUT);

pinMode(3, OUTPUT);

pinMode(4, OUTPUT);

}

void LEDDisplay(int count)

{ switch(count) // Each case value also corresponds to the decimal value. Ex) Case 0 is decimal 0 and so on.

{ case 0: digitalWrite(7, LOW);

digitalWrite(8, LOW);

digitalWrite(9, LOW);

digitalWrite(10, LOW);

digitalWrite(11, LOW);

digitalWrite(12, LOW);

digitalWrite(13, HIGH);

break;

case 1: digitalWrite(7, HIGH);

digitalWrite(8, LOW);

digitalWrite(9, LOW);

digitalWrite(10, HIGH);

digitalWrite(11, HIGH);

digitalWrite(12, HIGH);

digitalWrite(13, HIGH);

break; //Fill in the missing cases here..

default:

// Display letter 'd'..

digitalWrite(7, HIGH);

digitalWrite(8, LOW);

digitalWrite(9, LOW);

digitalWrite(10, LOW);

digitalWrite(11, LOW);

digitalWrite(12, HIGH);

digitalWrite(13, LOW);

}//switch-case

}//function

void DACInput(int counter2)

{ //This function sets the three pins connected to the R2R ladder input and makes them LOW/HIGH // depending on the current digital(decimal) value displayed on the LED by converting them into // binary (LOW/HIGH) for each pin. //This is nothing related to the LED so no reverse logic is used.

switch(counter2)

{ case 0: // 000 = 0

digitalWrite(2, LOW);

digitalWrite(3, LOW);

digitalWrite(4, LOW);

break;

case 1: // 001 = 1

digitalWrite(2, LOW);

digitalWrite(3, LOW);

digitalWrite(4, HIGH);

break;

case 2: // 010 = 2

digitalWrite(2, LOW);

digitalWrite(3, HIGH);

digitalWrite(4, LOW);

break;

case 3: // 011 = 3

digitalWrite(2, LOW);

digitalWrite(3, HIGH);

digitalWrite(4, HIGH);

break;

// Fill in the missing cases..

default: // All low

digitalWrite(2, LOW);

digitalWrite(3, LOW);

digitalWrite(4, LOW);

}//switch-case

}//DACInput function

boolean waitForINCRButtonPush(boolean lastIncrSwitchState)

{

boolean currentIncrSwitchState = digitalRead(incrButtonPin);

if(lastIncrSwitchState != currentIncrSwitchState) delay(20);

currentIncrSwitchState = digitalRead(incrButtonPin);

return currentIncrSwitchState;

}

boolean waitForDECRButtonPush(boolean lastDecrSwitchState)

{ //This function waits for a button push and also debounces it..

boolean currentDecrSwitchState = digitalRead(decrButtonPin);

if(lastDecrSwitchState != currentDecrSwitchState) delay(20);

currentDecrSwitchState = digitalRead(decrButtonPin);

return currentDecrSwitchState;

}

void loop()

{

//This is waiting for the increment button push and also debounces it..

IncButtonCurrent = waitForINCRButtonPush(IncButtonLast);

if(IncButtonLast == LOW && IncButtonCurrent == HIGH)

{ counter++; //Advancing count by 1 since increment button was pushed.

}

////This is waiting for the decrement button push and also debounces it..

DecButtonCurrent = waitForDECRButtonPush(DecButtonLast);

if(DecButtonLast == LOW && DecButtonCurrent == HIGH)

{ ; //Fill in the missing line: Hint: Decrement what?

if(counter<0)

;//Fill in missing line: Hint: Ensures wrap around back to 7 if decrement occurs at 0

} //Modulo 8 will ensure our values dont exceed 7 and wrap-around

counter = ; // Fill in missing parts here: Hint: Perform a modulo 8 operation.

//Display values on the 7-segment LED

LEDDisplay(Fill in missing part);

//Set the binary value for each of the three pins connected to the R2R Ladder(DAC).

DACInput(Fill in missing part);

//Current states become the previous states for the next automatic call to the loop()

IncButtonLast = IncButtonCurrent;

DecButtonLast = DecButtonCurrent;

}//loop()

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

Medical Image Databases

Authors: Stephen T.C. Wong

1st Edition

1461375398, 978-1461375395

More Books

Students also viewed these Databases questions

Question

Show that (p q) and p q are logically equivalent.

Answered: 1 week ago

Question

discuss the four components of effective leadership.

Answered: 1 week ago