Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Lab 1

1. The first activity creates a toggle switch button using an Arduino board. The important commands
used in this activity are:

int pinLed = 10 and int pinSwitch = 2: These commands define the pins used for the LED and switch
respectively.

boolean oldSwitchState = LOW, boolean newSwitchState = LOW, and boolean LEDstatus = LOW: These
commands declare the variables that will hold the old and new switch states, as well as the status of the
LED.

pinMode(pinLed, OUTPUT) and pinMode(pinSwitch, INPUT): These commands set the pin modes to
either output or input.

newSwitchState = digitalRead(pinSwitch): This command reads the current state of the switch.

if ( newSwitchState != oldSwitchState ): This line checks if there is a change in the state of the switch.

digitalWrite(pinLed, HIGH) and digitalWrite(pinLed, LOW): These commands set the LED to turn on or
off.

The second activity is an example of LED fading in and out using the analogWrite command. The
important commands used in this activity are:

int ledPin = 9: This command defines the pin used for the LED.

analogWrite(ledPin, fadeValue): This command sets the brightness level of the LED based on the
fadeValue variable.

for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5): This line initializes the fadeValue variable and
sets the increment by which the LED will fade in.

for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5): This line initializes the fadeValue variable and
sets the decrement by which the LED will fade out.

delay(30): This command sets a delay of 30 milliseconds before the next iteration of the loop, creating a
smoother fade effect.

2. In the first activity, I learned how to create a toggle switch button using an Arduino board. This
involves defining the pins for the LED and switch, setting the pin modes to input or output, and using the
digitalRead and digitalWrite commands to read and control the state of the switch and LED.

In the second activity, I learned how to use the analogWrite command to fade an LED in and out. This
involves defining the pin used for the LED, setting the brightness level of the LED using the analogWrite
command, and using for loops with delay to gradually increase or decrease the brightness level of the
LED.
These two activities demonstrate different ways to control the behavior of an LED using an Arduino
board, either by toggling it on and off using a switch, or by gradually fading it in and out using the
analogWrite command.

You might also like