Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help. This is for the arduino uno and arduino IDE. As you learned in this weeks lab intro, one common method of outputting an

Please help. This is for the arduino uno and arduino IDE.

As you learned in this weeks lab intro, one common method of outputting an effective analog signal is to use pulse width modulation. During the in-class activities, you used this to control the motor speed. In this homework assignment you will use PWM to control the brightness of an LED. Rather than sending the PWM signal to the chip enable pin of the motor driver, you will be sending the PWM signal to the onboard LED.

As an example, an LED lit with a PWM signal at 50% duty cycle would appear less bright as the same LED that was lit continuously. However, in order for the effect to be convincing, the frequency must be high enough that the switching is imperceptible. Suggested values for the "total period" are on the order of 200 500 s (microseconds).

In this problem, you will program a sketch that takes as input the desired brightness and then using PWM, light the onboard LED accordingly. Because humans perceive light logarithmically, the following brightness index vs duty cycle should be used:

Brightness Index

Duty cycle

1

12.6

2

15.8

3

20.0

4

25.1

5

31.6

6

39.8

7

50.1

8

63.1

9

79.4

10

100.0

After the user inputs the desired brightness, the LED should turn on to that brightness for exactly 2 seconds and then turn off. At that point, the user can then input another brightness index.

The code should respond correctly even if the user inputs a brightness index value not in the table. For example, if the user enters the value 4.5, the code should use a duty cycle of:

(25.1%+36.1%)/2 = 56.7%

Note that the code will need to figure out which to duty-cycle values of the table to use given the user input. In the example above we averaged 25.1 and 31.6 because a brightness index of 4.5 is exactly in the middle of the the brightness indices of 4 and 5.

More generally, if the desired value is closer to one of the values in the table than the other, it should be weighted more heavily. This approach is known as linear interpolation. Here is the general formula:

image text in transcribed

where

image text in transcribed

Finally, to learn how to read in a floating point number in Arduino, study the following example code and/or try it out on your Uno. Note, make sure you have the correct board selected, otherwise this code will not compile.

void setup()

{

Serial.begin(9600);

Serial.println("starting program");

}

void loop()

{

String pi;

pi = "3.14153";

float X = pi.toFloat();

Serial.print("Pi = ");

Serial.println(X, 3);

while(1) {}

}

1. Using the Serial Monitor read in a string and convert the string to a floating point number. This floating point number represents the desired brightness index. Assume the input value will be between 1 and 10.

2. Determine the nearest two index numbers in the brightness index / duty-cycle table and use linear interpolation to compute the duty cycle for the brightness index that was input by the user.

3. Turn on the on-board LED at the appropriate duty cycle for exactly 2 seconds. Then turn off the LED and wait for the user to input another brightness index.

Code should be thoroughly commented (most lines should have comments). If you find you have difficulty observing differences on the Arduino board, use an external LED and current limiting resistor.

fi * (S I) + T * S = 0 fi * (S I) + T * S = 0

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

DB2 9 For Linux UNIX And Windows Advanced Database Administration Certification Certification Study Guide

Authors: Roger E. Sanders, Dwaine R Snow

1st Edition

1583470808, 978-1583470800

More Books

Students also viewed these Databases questions