0% found this document useful (0 votes)
13 views

Code For Interface 2

This code defines constants for 8 LED pins and 2 button pins. It sets the pin modes in setup() and reads the button states in loop(). If button 1 is pressed, it will light up the LEDs in sequence. If button 2 is pressed, it will light up LED 8. The LEDs are turned on for 200ms and then off for 200ms in a repeating pattern.

Uploaded by

Cali Lux
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Code For Interface 2

This code defines constants for 8 LED pins and 2 button pins. It sets the pin modes in setup() and reads the button states in loop(). If button 1 is pressed, it will light up the LEDs in sequence. If button 2 is pressed, it will light up LED 8. The LEDs are turned on for 200ms and then off for 200ms in a repeating pattern.

Uploaded by

Cali Lux
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Code for Interface 2 digitalWrite(LED1, HIGH);

const int buttonPin1 = 2; delay(200);


const int buttonPin2 = 4; digitalWrite(LED2, HIGH);
const int LED1 = 13; delay(200);
const int LED2 = 12; digitalWrite(LED3, HIGH);
const int LED3 = 11; delay(200);
const int LED4 = 10; digitalWrite(LED4, HIGH);
const int LED5 = 9; delay(200);
const int LED6 = 8; digitalWrite(LED5, HIGH);
const int LED7 = 7; delay(200);
const int LED8 = 6; digitalWrite(LED6, HIGH);
delay(200);
int buttonState1 = 0; digitalWrite(LED7, HIGH);
int buttonState2 = 0; delay(200);
digitalWrite(LED8, HIGH);
void setup() { delay(200);
pinMode(LED1, OUTPUT); digitalWrite(LED1, LOW);
pinMode(LED2, OUTPUT); delay(200);
pinMode(LED3, OUTPUT); digitalWrite(LED2, LOW);
pinMode(LED4, OUTPUT); delay(200);
pinMode(LED5, OUTPUT); digitalWrite(LED3, LOW);
pinMode(LED6, OUTPUT); delay(200);
pinMode(LED7, OUTPUT); digitalWrite(LED4, LOW);
pinMode(LED8, OUTPUT); delay(200);
pinMode(buttonPin1, INPUT); digitalWrite(LED5, LOW);
pinMode(buttonPin2, INPUT); delay(200);
} digitalWrite(LED6, LOW);
delay(200);
void loop() { digitalWrite(LED7, LOW);
delay(200);
buttonState1 = digitalRead(buttonPin1); digitalWrite(LED8, LOW);
buttonState2 = digitalRead(buttonPin2); delay(200);
}
// check if the pushbutton is pressed. If it is, the if (buttonState2 == HIGH) {
buttonState is HIGH:
digitalWrite(LED8, HIGH);
if (buttonState1 == HIGH) {
delay(200);
// turn LED on:
digitalWrite(LED7, HIGH); digitalWrite(LED7, LOW);
delay(200); delay(200);
digitalWrite(LED6, HIGH); digitalWrite(LED6, LOW);
delay(200); delay(200);
digitalWrite(LED5, HIGH); digitalWrite(LED5, LOW);
delay(200); delay(200);
digitalWrite(LED4, HIGH); digitalWrite(LED4, LOW);
delay(200); delay(200);
digitalWrite(LED3, HIGH); digitalWrite(LED3, LOW);
delay(200); delay(200);
digitalWrite(LED2, HIGH); digitalWrite(LED2, LOW);
delay(200); delay(200);
digitalWrite(LED1, HIGH); digitalWrite(LED1, LOW);
delay(200); delay(200);
digitalWrite(LED8, LOW); }
delay(200); }

You might also like