
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
how to write a main function that combine all of these different functions so after switchButton is pressed toggled led run and after that RGBled will run and after pressing start_button the printWaterLevel and readWaterTemperature will run and lastly without pressing anything run_washing_machine_cycle and check_force_sensor will run and after pressing switchButton again everything turn off, the code does work and this pins are identified but not in the required sequence
// Function to toggle the LEDs
void toggleLEDs() {
staticbool ledsOn =false; // Initialize LED state to off
ledsOn = !ledsOn; // Toggle LED state
if (ledsOn) { // Turn on all LEDs
ledRed = 1;
ledGreen1 = 1;
ledGreen2 = 1;
ledGreen3 = 1;
} else { // Turn off all LEDs
ledRed = 0;
ledGreen1 = 0;
ledGreen2 = 0;
ledGreen3 = 0;
LedRed.write(0); // Turn off RGB LED
LedGreen.write(0);
LedBlue.write(0);
}
if (ledsOn && switchCount ==2) { // If LEDs are turned on and switch has been pressed twice
ledRed = 0; // Turn off red LED
}
}
void RGBled() {
// Read potentiometer value and map it to the range [0,1]
float value =pot.read();
// Map potentiometer value to different ranges for each color
LedRed.write(value *0.5f); // Red - maps from [0, 0.5] range
LedGreen.write((value -0.5f) *2.0f); // Green - maps from [0.5, 1] range
LedBlue.write(1.0f- value); // Blue - maps from [1, 0] range
}
void run_washing_machine_cycle() {
bool wash_done =false;
bool rinse_done =false;
bool dry_done =false;
bool cycle_complete =false;
while (!cycle_complete) {
// Wash cycle
ledGreen1 = 1;
display = 0b00010000; // Display "wash" on 7 segment display
printf("Wash cycle started.\n");
int cycle_time_left =10;
while (cycle_time_left >0) {
display = (int_to_display(cycle_time_left / 10) << 8) | int_to_display(cycle_time_left % 10);
ThisThread::sleep_for(WAIT_TIME_MS);
cycle_time_left--;
}
cycle_time_left = 5;
wash_done = true;
ledGreen1 = 0;
// Rinse cycle
ledGreen2 = 1;
display = 0b00100000; // Display "rinse" on 7 segment display
printf("Rinse cycle started.\n");
while (cycle_time_left >0) {
display = (int_to_display(cycle_time_left / 10) << 8) | int_to_display(cycle_time_left % 10);
ThisThread::sleep_for(WAIT_TIME_MS);
cycle_time_left--;
}
cycle_time_left = 5;
rinse_done = true;
ledGreen2 = 0;
// Dry cycle
ledGreen3 = 1;
display = 0b01000000; // Display "dry" on 7 segment display
printf("Dry cycle started.\n");
while (cycle_time_left >0) {
display = (int_to_display(cycle_time_left / 10) << 8) | int_to_display(cycle_time_left % 10);
ThisThread::sleep_for(WAIT_TIME_MS);
cycle_time_left--;
}
cycle_time_left = 0;
dry_done = true;
ledGreen3 = 0;
// Cycle complete
cycle_complete = true;
ledGreen1 = 0;
ledGreen2 = 0;
ledGreen2 = 0;
ledGreen3 = 0;
ledRed = 1;
play_buzzer();
}
}
void printWaterLevel() {
// Read water level sensor value and print it to the serial monitor
int waterLevel =analog_value.read_u16();
if (waterLevel <=0) {
printf("%d | Empty\n", waterLevel);
} else if (waterLevel <= 150) {
printf("%d | Water level is low\n", waterLevel);
} else if (waterLevel <= 400) {
printf("%d | Water level is medium\n", waterLevel);
} else {
printf("%d | Water level is high\n", waterLevel);
}
}
void readWaterTemperature() {
// Read the analog input for water temperature sensor and convert it to a temperature value
float temp =water_temp_sensor.read() *100;
if(temp >30.0) {
ledRed = 1; // Turn on LED1 and turn off all other LEDs
ledGreen1 = 0;
ledGreen2 = 0;
ledGreen3 = 0;
} else {
ledRed = 0; // Turn off LED1 and turn on all other LEDs
ledGreen1 = 1;
ledGreen2 = 1;
ledGreen3 = 1;
}
}
void check_force_sensor() {
// Read the analog input for force sensor and convert it to a force value
float force =force_sensor.read() *100;
if(force >80.0) {
printf("Open door\r\n"); // Send a message over serial to indicate that the door should be opened
}
}
int main() {
printf("System started\n");
while (1) {
// Check if switch is pressed
if (switchButton ==0) {
switchCount++; // Increment switch count
toggleLEDs(); // Toggle the LEDs
RGBled();
while (switchButton ==0); // Wait until switch is released
}
}
RGBled();
readWaterTemperature();
printWaterLevel();
}
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 3 steps

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Choose the joy stick statements in the list below. O The readings from a joystick should span -512 to 512. O An analog joystick is equivalent to two potentiometers. O When the joystick is in the neutral position, the readings on the x and y axis should be near 512 (on an Arduino analog input pin). You can use a joystick to control two motors.arrow_forwardYour program should create a counter variable. Counting details in part 1. When the programfinally completes, the program should output the number of times the user depressed CTRL-C.(1) The first is to handle the SIGINT (CTRL-C, ^C) signal. This signal handler should incrementthe counter.The signal handler should also contain a MAX value (say 5) that is used. In the case thatthe maximum is reached:• a message indicating that the MAX has been exceeded should be output• the signal handler should be "deactivated" so that the next instance of the ^Csignal causes the program to terminate.(2) The second signal handler should deal with the SIGQUIT signal (CTRL-\, ^\). If the usersends this signal, the signal handler should create a new process (fork).This child process should print a message and then send a SIGUSR1 signal (using kill())to its parent. The child should terminate with no error code. This must be accomplishedwithout using any of the exec() family of calls.The parent side of the…arrow_forwardbe fadt pleasearrow_forward
- Write a postcondition, event-controlled loop (i.e., a while loop), using a flag variable, that prints the numbers 8, 14, 20, 26, 32, and 38 to the terminal (one per line).arrow_forwarduse pseudocode in designing the logic Design an application for Bob’s E-Z Loans. The application accepts a client’s loan amount and monthly payment amount. Output the customer’s loan balance each month until the loan is paid off.arrow_forwardWhich type(s) of loop would be best to run a weather model for 1000 cycles? A do-while loop A for loop A while loop Either a do-while loop or a while loop Either a for loop or a while loop Either a do-while loop, for loop or a while looparrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education