AnalogWrite() function.pptxLight Indicator Replacement of traditional incandescent light bulbs LED Display Decorative Lighting Surgical Lights

KameshvraDelaCruz 9 views 20 slides Mar 03, 2025
Slide 1
Slide 1 of 20
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20

About This Presentation

Discuss the LED as an output device,
Identify and explain in the sketch that will control the LED as an analog output device,
Discuss the while statement as part of the looping control structure,
Create a sketch that will make use of the while statement to control an LED, and
Build a digital circuit...


Slide Content

AnalogWrite () Function

Objectives Discuss the LED as an output device, Identify and explain in the sketch that will control the LED as an analog output device, Discuss the while statement as part of the looping control structure, Create a sketch that will make use of the while statement to control an LED, and Build a digital circuit using LED as an analog output device.

LED Applications Light Indicator Replacement of traditional incandescent light bulbs LED Display Decorative Lighting Surgical Lights

const int LEDpin = 3; This variable represents where the LED is connected. Pin 3 is one of the PWM (pulse width modulation) pins that are used to control analog output devices.

pinMode ( LEDpin , OUTPUT); The pinMode () function prepares LEDpin (PWM pin 3) as an output pin that can be used to control analog devices.

analogWrite ( LEDpin , 230); The analogWrite () function is used to control an analog device, which in this case is the LED connected to PWM 3. As an analog output device, LED is controlled by specifying the LED brightness from 0 (lowest value) to 255 (highest value).

AnalogWrite () function Controlling LED brightness for different purposes can be done via the use of PWM pins of your Arduino board (~) even in the absence of a built-in DAC (digital to analog converter), PWM makes it possible to allow digital signal to function as an analog output. Syntax analogWrite (pin, value); Parameters pin: PWM pins ~3, ~5, ~6, ~9, ~10, and ~11 value: from 0 to 255

Looping Control Structure – While Statement Sometimes there is a need for some part of the code to be executed more than once. This can be done by either repeating the code in the program or using loops. In times where some part of the code needs to be executed may times it may not be practical to repeat the code, alternatively, a loop can be used. while loop – this is constructed with a condition or expression and a single command or a block of commands that must run in a loop.

while loop – this is constructed with a condition or expression and a single command or a block of commands that must run in a loop. Syntax //FOR SINGLE STATEMENT while(condition) statement; //FOR SINGLE STATEMENT while(condition) { //BLOCK OF STATEMENTS statement 1 statement 2 … … statement n; } The statements within the while loop would continue to be executed while the condition being tested remains TRUE. When the condition becomes FALSE, the control passes to the first statement that follows the body of the while loop.

int number = 1; A looping control structure that has three basic parts (initialization, condition, increment/decrement) that needs to be present to somehow avoid an infinite loop. The variable number and 1 as its initial value is the initialization; this basically dictates the start of the loop.

Serial.begin (9600); This code will open up the serial communication between the serial monitor and the microcontroller. It will be used to check and display the value coming from the microcontroller unit.

while (number <=5) This is a conditional statement that dictates whether the block of statements will be executed or skipped. if the result of the condition is TRUE then it repeats the block of statements but if it is FALSE then the loop ends.

number++; number = number + 1 The given variable (number) will be incremented by 1. The increment/decrement is the 3 rd important part of a looping statement because it will trigger the end of the loop once it comes back to the condition.

START number = 1 number < = 5 END Print number number ++ A A TRUE FALSE LOGICAL FLOW OF THE WHILE STATEMENT

ACTIVITY Create an Arduino sketch that will generate and display the given output below in the Serial Monitor. Take note that all the numbers must be generated inside the while statement. Sample Output Looping Control Structure While loop statement 10 8 6 4 2 0 <<END OF THE PROGRAM>>

ACTIVITY Create an Arduino sketch that will generate and display the given output below in the Serial Monitor. Take note that all the numbers must be generated inside the while statement. B. Sample Output Looping Control Structure While loop statement 50 60 70 80 81 82 83 83 85 <<END OF THE PROGRAM>>

ACTIVITY Create an Arduino sketch that will generate and display the given output below in the Serial Monitor. Take note that all the numbers must be generated inside the while statement. C. Sample Output Looping Control Structure While loop statement 20 21 23 24 25 40 41 42 43 44 45 <<END OF THE PROGRAM>>

ACTIVITY Create an Arduino sketch that will generate and display the given output below in the Serial Monitor. Take note that all the numbers must be generated inside the while statement. D. Sample Output Looping Control Structure While loop statement 80 5 81 4 82 3 83 2 84 1 <<END OF THE PROGRAM>>

Performance Task Assemble a digital prototype of a light emitting diode that gradually fades in and then fades out meaning that the brightness should start from 0 to 255 back to 0 and this series of actions will be repeated inside a void loop() function. Set a 10-millisecond delay on each change of the LED brightness. Additional points will be given if the Arduino sketch will only use one while looping statement and one variable that will represent the brightness of the LED.
Tags