RUNNING LED-ARDUINO NANO
- Rabu, 20 November 2024
- Elektronika
- Administrator
- 0 komentar
ARDUINO NANO V3
CARA MERANGKAI :
- ARDUINO NANO V3 (+SOKET KLU DIPERLUKAN)
- IC REGULATOR L7805 (BILA DIPERLUKAN 12->5V)
- BATERE KOTAK 9V
- KABEL JUMPER
- LED PUTIH (NYALA PUTIH ATAU BIRU)
- RESISTOR 100 OHM
- BREAD BOARD
LANGKAH KERJA :
- RANGKAIAN LED SEMUA SISI KAKI POSITIF /KAKI PANJANG(FILAMEN KECIL) PASANG DI SISI LUAR BREADBOARD (JADI SATU)
- TAMBAH R DI SETIAP LED (KAKI NEGATIF/KAKI PENDEK->FILAMEN BESAR)
- HUBUNGKAN PIN A0-A5, PIN 4-13 ATAU D4-D13
- PIN D2 DAN D3 DIJADIKAN KONTROL (KE SWITCH)
- HUBUNGKAN BATERE 5V
LANGKAH KERJA SELANJUTNYA :
- HUBUNGKAN PIN_5V ARDUINO KE KAKI POSITIF LED
- UPLOAD PROGRAM KE ARDUINO
- HUBUNGKAN SWITCH 2 PIN DEPAN DIHUBUNGKAN DENGAN POSITIF 5V PADA KAKI LED POSITIF DAN 2 KAKI BELAKANG PADA MASING-MASING PIN D2 DAN D3
- SILAHKAN UJICOBA
KODING :
int pins[] = {A0,A1,A2,A3,A4,A5,4,5,6,7,8,9,10,11,12,13};
int v[16];
long t[2];
bool on = false;
int detime = 40;
int mode = 0;
const byte interruptPin1 = 2;
void setup() {
Serial.begin(9600);
for(int p=0;p<15;p++)
{
pinMode(pins[p], INPUT);
}
t[0]=millis()+3000;
t[1]=millis()+3200;
pinMode(interruptPin1, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interruptPin1), blink, FALLING);
}
int cc;
long pulse;
void blink()
{
Serial.println(digitalRead(interruptPin1));
mode++;
if(mode>8)
mode=1;
}
void loop()
{
//Serial.println("Loop");
if(millis()<=t[0])
{
for(int p=0;p<=15;p++)
{
if(digitalRead(pins[p])==1)
{
v[p]++;
}
else
{
v[p]--;
}
}
String o="";
for(int p=0;p<15;p++)
{
o = o + String(v[p]) + ",";
}
}
else if(millis()>=t[0] && millis()<t[1])
{
int j=0;
for(int p=0;p<15;p++)
{
if(v[p]>detime)
{
pinMode(pins[p], OUTPUT);
digitalWrite(pins[p], 1);
}
}
}
else
{
if(mode==1)
{
for(int p=0;p<15;p++)
{
if(v[p]>detime)
{
digitalWrite(pins[p], 0);
delay(30);
}
}
for(int p=0;p<15;p++)
{
if(v[p]>detime)
{
digitalWrite(pins[p], 1);
delay(30);
}
}
delay(0);
}
if(mode==2)
{
for(int p=15;p>=0;p--)
{
if(v[p]>detime)
{
digitalWrite(pins[p], 0);
delay(30);
}
}
for(int p=15;p>=0;p--)
{
if(v[p]>detime)
{
digitalWrite(pins[p], 1);
delay(30);
}
}
delay(0);
}
if(mode==3)
{
for(int p=0;p<15;p++)
{
if(v[p]>detime)
{
digitalWrite(pins[p], 0);
delay(80);
digitalWrite(pins[p], 1);
}
}
}
if(mode==4)
{
for(int p=15;p>=0;p--)
{
if(v[p]>detime)
{
digitalWrite(pins[p], 0);
delay(80);
digitalWrite(pins[p], 1);
}
}
}
if(mode==5)
{
for(int p=15;p>=0;p--)
{
if(v[p]>50)
{
for(int q=0;q<=p;q++)
{
if(v[q]>detime)
{
digitalWrite(pins[q], 0);
delay(30);
digitalWrite(pins[q], 1);
}
}
digitalWrite(pins[p], 0);
}
}
delay(200);
for(int p=0;p<15;p++)
{
if(v[p]>detime)
{
digitalWrite(pins[p], 1);
}
}
delay(50);
}
if(mode==6)
{
for(int p=0;p<15;p++)
{
if(v[p]>50)
{
for(int q=15;q>=p;q--)
{
if(v[q]>detime)
{
digitalWrite(pins[q], 0);
delay(30);
digitalWrite(pins[q], 1);
}
}
digitalWrite(pins[p], 0);
}
}
delay(200);
for(int p=0;p<15;p++)
{
if(v[p]>detime)
{
digitalWrite(pins[p], 1);
}
}
delay(50);
}
if(mode==7)
{
for(int p=0;p<15;p++)
{
if(v[p]>detime)
{
digitalWrite(pins[p], 0);
}
}
delay(100);
for(int p=0;p<15;p++)
{
if(v[p]>detime)
{
digitalWrite(pins[p], 1);
}
}
delay(100);
}
if(mode==8)
{
int pertwo = 0;
for(int p=0;p<15;p++)
{
if(v[p]>detime)
{
pertwo++;
}
}
pertwo = pertwo/2;
int pertwo1 = 0;
for(int p=0;p<15;p++)
{
if(v[p]>detime)
{
if(pertwo1<pertwo)
{
digitalWrite(pins[p], 0);
}
else
{
digitalWrite(pins[p], 1);
}
pertwo1++;
}
}
delay(200);
pertwo1 = 0;
for(int p=0;p<15;p++)
{
if(v[p]>detime)
{
if(pertwo1>=pertwo)
{
digitalWrite(pins[p], 0);
}
else
{
digitalWrite(pins[p], 1);
}
pertwo1++;
}
}
delay(200);
}
}
}
Semoga bermanfaat...