Question
in C++ /* * combo_lock_app.cpp //////////////////////////////////////////////////////////////////////////////////////// /////// DELIVERABLE 1: Put your name and date above mine = shared credit for code. ///// //////////////////////////////////////////////////////////////////////////////////////// * *
in C++
/*
* combo_lock_app.cpp
////////////////////////////////////////////////////////////////////////////////////////
/////// DELIVERABLE 1: Put your name and date above mine = shared credit for code. /////
////////////////////////////////////////////////////////////////////////////////////////
*
* Created: 1/16/2020 7:53:34 PM
* Author : carrolls
*/
// Hardware Dependencies: Momentary switch to ground on PC0 and PC1. LED to ground on PB5.
#include
#include "combo_lock.h"
void blink_thrice()
{
for (int8_t n = 0; n < 3; n++)
////////////////////////////////////////////////////////////////////////////////////////////
// DELIVERABLE 2: YOU WRITE CODE TO BLINK ONCE, FOR ABOUT A SECOND; LET THE LOOP TRIPLE IT.
// GIVEN FUNCTIONS = void LED_on();void LED_off(); They do the obvious things.
////////////////////////////////////////////////////////////////////////////////////////////
}
int main(void)
{
blink_thrice();
while (1)
{
static int combo_correct_bits = 0;
// Busy-wait for a button activity
while (!C_button_read(0) && !C_button_read(1)) {;}
bool c0 = C_button_read(0); // Read the two buttons
bool c1 = C_button_read(1);
switch(combo_correct_bits) // Decide if correct
{
case -1: for (int32_t n = 0; n< 1234567; n++){;}
blink_thrice();
combo_correct_bits = 0;
break;
case 0: if (c0 == BTN_ACTIVE && c1==BTN_INACTIVE){
combo_correct_bits++;
} else {
combo_correct_bits = -1;
}
break;
////////////////////////////////////////////////////////////////////////////////////////////
// DELIVERABLE 3: WRITE CASES 1 & 2 to run LED_on() only if the user presses exactly 0-0-1.
// If they hit a wrong button, set combo_correct to -1 and let case -1
// blink at them (after a delay). Use c0 and c1, not C_button_read().
////////////////////////////////////////////////////////////////////////////////////////////
case 1:
case 2:
default: combo_correct_bits = -1;
}
//////////////////////////////////////////////////////////////////////////////////////////
// DELIVERABLE 4: YOU WRITE A LOOP HERE TO WAIT FOR THE USER TO LET GO OF THE BUTTON
// DELIVERABLE 5: WRITE A NOTE - WHAT WILL HAPPEN IF YOU OMIT THIS?
///////////////////////////////////////////////////////////////////////////////////////////
}
////////////////////////////////////////////////////////////////////////////////////////////
// DELIVERABLE 6: Show me that your machine works. YOU decide how; I'll call your experiment
// "convincing" or "unconvincing." HINT: include pressing BOTH buttons at once. Do you need
// to reset your system after each error, or can you just dial a new combo after a failure?
// What about after a success?
//
// DELIVERABLE 7: WRITE YOUR TESTS AS A CHECKLIST.
////////////////////////////////////////////////////////////////////////////////////////////
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started