tag:blogger.com,1999:blog-60255810176462355722024-03-05T19:00:22.783-08:00DIYNanjar Syabanulhttp://www.blogger.com/profile/15747580028718760610noreply@blogger.comBlogger1125tag:blogger.com,1999:blog-6025581017646235572.post-20315650524441209422015-07-21T20:45:00.000-07:002015-07-21T21:16:16.849-07:00Running LED dan Button - Arduino<div>
rangkailah rangkaian berikut</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0BV-5t4PPONODK2hopVBi_Mi7YYhNii694WFuaCT8QxqlxhyphenhyphenINV4iGXGMOSMJ5dwkxwRXouB0JsyhLPnbnWBFo48e8P7qIRDeJk0LGsLiqJBplbG_lCguayP4Qhh5c5T9jY7xaVRBDFsu/s1600/run.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0BV-5t4PPONODK2hopVBi_Mi7YYhNii694WFuaCT8QxqlxhyphenhyphenINV4iGXGMOSMJ5dwkxwRXouB0JsyhLPnbnWBFo48e8P7qIRDeJk0LGsLiqJBplbG_lCguayP4Qhh5c5T9jY7xaVRBDFsu/s320/run.jpg" width="320" /></a></div>
<br />
<br />
upload sketch berikut kearduino<br />
<br />
<br />
<pre data-codetype="JavaScriptku" title="sketch"><code class="language-javascript">
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();}
}</code></pre>Nanjar Syabanulhttp://www.blogger.com/profile/15747580028718760610noreply@blogger.com1