Question: Whistle Timer /// loudness sensor, LED bar///// see if you can whistle long enough to fill the lights on the LED bar This lab involves
| Whistle Timer /// | loudness sensor, LED bar///// | see if you can whistle long enough to fill the lights on the LED bar |
This lab involves using a loudness sensor to activate a while loop. The purpose is to set up the sensor so that while it detects a whistle it will cause the LED to display a timer which increases incrementally as time progresses. When the loudness sensor is no longer activated the timer will stop, ending the loop. When another whistle is detected the timer will restart.
Implementation considerations: While the first condition (Has user activated loudness sensor?) remains false, no sound is generated. When a whistle is detected and the timer begins, the timer will continue until the condition is again evaluated as false, ending the loop. As long as the sensor remains activated, the condition will continue to be evaluated as true and the timer loop will continue. While the sensor remains activated, the LED timer bar will increase incrementally, displaying one additional bar for each second of continual activation.
The LED bar increases by one block each second; the LCD shows the users whistle time
-----------------------------------
code:
////INCLUDE STATEMENTS // Including the libraries with the functions we need for this program #include
////FUNCTION DECLARATIONS - Declarations for functions defined in this file void waitForReset();
////MAIN - Every C++ program beings with main() function int main() {
//TODO - Define variables you might need throughout the code here (if needed) //Suggestions? Variables to store sound threshold, level to display on LED bar
//Required at beginning of each lab file - initialize Arduino and other hardware. initLab(); initBar();
//Required by Arduino - main() function must have this WHILE loop //Use it to keep the program running while (true == true) - ie forever! while ( true ) { //TODO - Implement design (pseudocode) here in C++ //- You SHOULD BE USING YOUR OWN WHILE LOOP with a reasonable logical condition //- If the loudness indicator is still above the threshold, add another bar to the LED bar //- You will need to wait a second before checking the loudness again //- The LCD is not explicitly used, but is there for you to output debug info //TODO - After the whistling has stopped, call function that waits for reset button to be pressed //You may also want to reset the bar level back to 0 }
//Every main() needs to return a value because its type is not void return 0; }
//TODO - Function contract and definition for waitForReset()
----------------------------------------
use some functions from this library
//General library functions
void initLab();
//LCD functions and variables
void initLCD(unsigned int r, unsigned int g, unsigned int b);
void printLCD(const String msg);
void printLCD(const float msg);
void clearLCD();
void backgroundLCD(unsigned int r, unsigned int g, unsigned int b);
//Temperature sensor-related functions and variables
const int B = 4275; // B value of the thermistor
const long R0 = 100000; // R0 = 100k
const int pinTempSensor = A0; // Grove - Temperature Sensor connect to A0
float calculateCelsius(int sensorValue);
void printCelsius(float c);
void printFahrenheit(float f);
void setTemperatureColour(float p);
//Rotary dial sensor functions and variables
const int ADC_REF = 5; //reference voltage of ADC is 5v
const int VCC = 5; //VCC of the grove interface
const int FULL_ANGLE = 300; //full value of the rotary angle
const int pinRotarySensor = A1; // Grove - Rotary Sensor connect to A1
//Light sensor functions and variables
const int pinLightSensor = A2; // Grove - Light Sensor connect to A2
//Speaker functions and variables
const int SPEAKER = 3; //Indicates speaker will be in D3
void playNote(int f);
//LED functions and variables
const int LED_1 = 2; //Indicates LED_1 will be in D2
void powerLED();
//Button functions and variables
const int BUTTON_1 = 8; //Indicates BUTTON_1 will be in D8
const int BUTTON_2 = 7; //Indicates BUTTON_2 will be in D7
const int BUTTON_3 = 6; //Indicates BUTTON_3 will be in D6
const int BUTTON_4 = 5; //Indicates BUTTON_4 will be in D5
//Note that to read button values, you will need to call the Arduino library function
// int val = digitalRead(int pinNumber);
// More info: https://www.arduino.cc/reference/en/language/functions/digital-io/digitalread/
//Button functions and variables
const int TILT_1 = 8; //Indicates TILT_1 will be in D8
const int TILT_2 = 7; //Indicates TILT_2 will be in D7
//Note that to read tilt sensor values, you will need to call the Arduino library function
// int val = digitalRead(int pinNumber);
// More info: https://www.arduino.cc/reference/en/language/functions/digital-io/digitalread/
//Ultrasonic functions and variables
const int trigPin = 9; //Trig - white Jumper
const int echoPin = 8; //Echo - yellow Jumper
long getSonicDistance();
//LED Bar functions and variables
const int clockPin = 5; //Clock Pin for LED Bar
const int dataPin = 4; //Data Pin for LED Bar
const bool orientation = true;
void initBar();
void setBarLevel(float level);
void setBarLED(int led, float brightness);
void toggleBarLED(int led);
void setBarBits(unsigned int bits);
//Servo functions and variables
const int SERVO_1 = 4; //Indicates TILT_1 will be in D4
void setServoPosition(float angle);
//Loudness sensor functions and variables
const int pinLoudnessSensor = A1;
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
