Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using a rotary sensor, check if the dial has been turned beyond a threshold and light an LED accordingly . DESIGN PART 2: Given your

Using a rotary sensor, check if the dial has been turned beyond a threshold and light an LED accordingly .

DESIGN PART 2: Given your project problem, write the decision that needs to be made in an if-then-(else) sentence. For example, if the problem were something like, "Using a thermometer, check to see if the temperature indicates you should wear a jacket", you could rewrite this as

if temperature is less than {insert value here}, then put on jacket.

With the light-speaker project, you want to play a noise when the light level is above 85%.

With the rotary-LED project, you want the LED to light up with the dial is turned over 200 degrees.

For the chosen project, come up with a test plan. Note that in addition to the output device mentioned, you will also be using the LCD screen which will show the sensor reading. Knowing this, the project youve chosen and the range of your sensor readings, come up with one way to test that your mathematical expression has been implemented correctly. Come up with two ways to know if your conditional flow control does what is expected.

--------------------------------------------------

cod:

////FUNCTION DECLARATIONS - Declarations for functions defined in this file float calculatePercent(float val, float minVal, float maxVal); void powerLED();

////MAIN - Every C++ program beings with main() function int main() {

//TODO - Define variable to store threshold based on Prep, and assign it correct (literal) value //Required at beginning of each lab file - initialize Arduino and other hardware. initLab(); //Reading the rotary dial sensor value int sensorValue = analogRead(pinRotarySensor); printLCD("a="); printLCD(sensorValue); //Using function defined during lab to convert sensor reading to percent float percent = calculatePercent(0,0,0 /*TODO - replace this will correct parameter*/); //TODO - Add conditional flow control here to light LED if rotary percentage above threshold

//Required by Arduino - main() function must have this WHILE loop while ( true ) { } //Every main() needs to return a value because its type is not void return 0; }

//OTHER FUNCTION DEFINITIONS /*calculatePercent * This function calculates percentage based on the value, minimum and maximum provided *Inputs * val - sensor reading * minVal - minimum sensor reading expected * maxVal - maximum sensor reading expected *Output * p - percent calculated */

//TODO - First write stub (empty) function based on the above //TODO - Then define function using expression from Preparation

/*powerLED * This function turns on a connected LED *Inputs - None *Output - None *Modifies * LED will turn on */ void powerLED() { digitalWrite(LED_1, HIGH); //set LED ON }

----------------------------

Some usful functions/

//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

#define SPEAKER 3 //Indicates speaker will be in D3

//LED functions and variables

#define LED_1 2 //Indicates LED_1 will be in D2

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

Database Reliability Engineering Designing And Operating Resilient Database Systems

Authors: Laine Campbell, Charity Majors

1st Edition

978-1491925942

More Books

Students also viewed these Databases questions

Question

=+Have you changed your name?

Answered: 1 week ago