[go: up one dir, main page]

0% found this document useful (0 votes)
20 views1 page

IOT prct4

The document contains an Arduino sketch that controls three LEDs using three corresponding buttons. Each button, when pressed, turns on its associated LED, and when released, turns it off. The setup function initializes the pins for the LEDs and buttons, while the loop function continuously checks the button states to control the LEDs.

Uploaded by

kudaratiarva
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views1 page

IOT prct4

The document contains an Arduino sketch that controls three LEDs using three corresponding buttons. Each button, when pressed, turns on its associated LED, and when released, turns it off. The setup function initializes the pins for the LEDs and buttons, while the loop function continuously checks the button states to control the LEDs.

Uploaded by

kudaratiarva
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

int redLedPin = 5;

int greenLedPin = 13;


int blueLedPin = 22;
int redButtonPin = 10;
int greenButtonPin = 18;
int blueButtonPin = 27;
void setup() {
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);
pinMode(5, OUTPUT);// Set the ledPin as output
pinMode(4, INPUT);// Set the buttonPin as input
pinMode(3, INPUT);
pinMode(2, INPUT);
}

void loop() {
int buttonState1 = digitalRead(4); // Read the button state

if (buttonState1 == HIGH) { // If the button is pressed


digitalWrite(7, HIGH); // Turn LED on
} else {
digitalWrite(7, LOW); // Turn LED off
}
int buttonState2 = digitalRead(3); // Read the button state

if (buttonState2 == HIGH) { // If the button is pressed


digitalWrite(6, HIGH); // Turn LED on
} else {
digitalWrite(6, LOW); // Turn LED off
}
int buttonState3 = digitalRead(2); // Read the button state

if (buttonState3 == HIGH) { // If the button is pressed


digitalWrite(5, HIGH); // Turn LED on
} else {
digitalWrite(5, LOW); // Turn LED off
}
}

You might also like