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

Led 02

This C++ code is designed for an Arduino setup that controls four output pins based on the input from two buttons. It shifts an LED indicator left or right depending on which button is pressed, cycling through the pins 4 to 7. The program includes a delay of 500 milliseconds between updates to the LED state.

Uploaded by

kangjoon1004
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)
8 views1 page

Led 02

This C++ code is designed for an Arduino setup that controls four output pins based on the input from two buttons. It shifts an LED indicator left or right depending on which button is pressed, cycling through the pins 4 to 7. The program includes a delay of 500 milliseconds between updates to the LED state.

Uploaded by

kangjoon1004
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

// C++ code

//
void setup()
{
pinMode(4,OUTPUT);pinMode(5,OUTPUT);
pinMode(6,OUTPUT);pinMode(7,OUTPUT);
pinMode(2,INPUT) ;pinMode(3,INPUT);
}

int bt1, bt2;


int ledPin=3;
int flag=1;
void loop()
{
bt1 = digitalRead(3);
bt2 = digitalRead(2);

if(bt1) flag=1;// left shift


if(bt2) flag=0;// right shift

if(flag)
{ledPin++; if(ledPin>7) ledPin=4;}
else
{ledPin--; if(ledPin<4) ledPin=7;}

if(ledPin==4) digitalWrite(4,HIGH);
else digitalWrite(4,LOW);
if(ledPin==5) digitalWrite(5,HIGH);
else digitalWrite(5,LOW);
if(ledPin==6) digitalWrite(6,HIGH);
else digitalWrite(6,LOW);
if(ledPin==7) digitalWrite(7,HIGH);
else digitalWrite(7,LOW);
delay(500);

You might also like