Running LED dan Button - Arduino
rangkailah rangkaian berikut
upload sketch berikut kearduino
int i,val;
int button1=8;
int button2=9;
unsigned char led[8]={~0x01, ~0x02, ~0x04, ~0x08, ~0x10, ~0x20, ~0x40, ~0x80};
unsigned char leda[8]={0b11111100, 0b11111001, 0b11110011, 0b11100111, 0b11001111, 0b10011111, 0b00111111, 0b01111111};
void ledplus()
{
for(i=0;i<=7;i++)
{
if(digitalRead(button2)==LOW)
{
return;// delay(500);
}
PORTD=led[i];
delay(300);
}
PORTD=0xC3; delay(1000);
for(i=7;i>=0;i--)
{
if(digitalRead(button2)==LOW)
{
return;//break; //delay(500);
}
PORTD=~led[i];
delay(200);
}
PORTD=0xFF;
}
void ledmin()
{
for(i=0;i<=7;i++)
{
if(digitalRead(button1)==LOW)
{
return;//break; //delay(500);
}
PORTD=leda[i];
delay(300);
}
//PORTD=0xC3; delay(1000);
for(i=7;i>=0;i--)
{
if(digitalRead(button1)==LOW)
{
return;//break; //delay(500);
}
PORTD=~leda[i];
delay(200);
}
PORTD=0xFF;
}
void setup() {
// put your setup code here, to run once:
PORTD=0xFF;
DDRD=0xFF;
pinMode(button1,INPUT_PULLUP);
pinMode(button2,INPUT_PULLUP);
}
void loop() {
// put your main code here, to run repeatedly:
if(digitalRead(button1)==LOW){ledplus();}
else if(digitalRead(button2)==LOW){ledmin();}
}
bang bisa ajarin ane gk... sry bang bru pertama kali nh...
BalasHapus