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

2 LED With A Push Button

This document declares integer variables to control LED pins and a button pin. It defines a setup void to initialize the pins and a loop void to read the button state and toggle the LED colors.

Uploaded by

Veni Hârâzuku
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)
36 views1 page

2 LED With A Push Button

This document declares integer variables to control LED pins and a button pin. It defines a setup void to initialize the pins and a loop void to read the button state and toggle the LED colors.

Uploaded by

Veni Hârâzuku
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 ledPin;

int ledRed = 11;


int ledBlue = 10;
int button = 7;
int val = 0; // untuk menghitung status pin variable
int currentState = 0;
int previousState = 0;
int counter = 0;

void setup() {
pinMode (ledPin, OUTPUT);
pinMode (ledRed, OUTPUT);
pinMode (ledBlue, OUTPUT);
pinMode (button, INPUT);

void loop() {
val = digitalRead (button);
if (val == HIGH) {
digitalWrite(ledPin, HIGH);
currentState = 1;
}else{
digitalWrite(ledPin, LOW);
currentState = 0;
}
if(currentState != previousState){
if(currentState == 1){
counter = counter +1;

}
}
if(counter == 0){
digitalWrite(ledRed, HIGH);
digitalWrite(ledBlue, LOW);
}
if(counter == 1){
digitalWrite(ledRed, LOW);
digitalWrite(ledBlue, HIGH);
}
if(counter == 2){
counter = 0;
}
previousState = currentState;
delay(100);
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy