Using a rotary sensor, check if the dial has been turned beyond a threshold and
ID: 3907170 • Letter: U
Question
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
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 you’ve 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
Explanation / Answer
Answer: The mathematical formula is as follows:
Sensor analog reading value ='a' degrees.
Given that full rotary angle =300 degrees
Rotary sensor reading as converted to percentage =p = (a /300) *100
Threshold of rotary sensor value =T = (200/300)*100 =66.67%
if rotary dial reading is greater than 20 degrees, then light up LED AND
if light level 'L' is greater than 85% , then play a sound
A0=temperature sensor
A1=Rotary sensor
A2=light sensor
The light level or light intensity will be determined by the calculated value of color temperature
Test plan:
The user has to fill in the Observed values in the table above . If observed values = the actual values , then mark the tes case is PASS else it is FAIL.
Sl No. Value of 'a' (Expected)Display value in LCD (Observed) Display in LCD Value of 'p'(calculated percentage) Comparision with Threshold (Expected )LED Light -ON/OFF (Observed)LED Light -ON/OFF) (Expected)Light Intensity level(L) as per color temperaure Speaker -ON/OFF (Observed) Speaker -ON/OFF Test Result (Pass/Fail) 1 a1<=200 deg a1 P1=(a1/300)*100 P1<=66.67 OFF L1=0 OFF 2 a2>200 deg a2 P2=(a2/300)*100 P2>66.67 ON When 0<L2<=85 OFF 3 a3>200 a3 P3=(a3/300)*100 P3>66.67 ON When L2>85 ONRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.