COUNTER UP & COUNTER DOWN
LAPORAN PRAKTEK MIKROKONTROLER
LEMBAGA PENDIDIKAN KEJURUAN TEKNIK
SMK PL LEONARDO KLATEN
Jl. Dr Wahidin Sudirohusodo no. 30 Klaten
I. TUJUAN
1. Siswa dapat merangkai rangkaian 7 segment.
2. Siswa dapat membuat program 7 segment.
3. Siswa dapat membuat program counter up dan counter down.
3. Siswa dapat membuat program counter up dan counter down.
II. ALAT & BAHAN
1. Komputer
2. Software Arduino
3. Protoboard
4. 7 Segment
5. Connector
6. Resistor
7. Arduino UNO
8. Push Button
8. Push Button
III. DESKRIPSI TUGAS
Membuat program & rangkaian 7 segment counter up dan counter down menggunakan 2 pb.
.
IV. LANGKAH KERJA
1. Langkah pertama buka software ARDUINO.
2. Rangkailah rangkaian 7 segment counter up dan counter down di protoboard.
3. Setelah terangkai, sambungkan arduino dengan pc laptop.
4. Buatlah program 7 segment counter up dan counter down.
5. Setelah itu save program.
6. Jika program telah tersimpan, upload program ke arduino.
Program:
7. Sebelum diupload, pastikan port yang tersambung adalah selain port COM1.
8. Lalu upload program tersebut.
Y. Prasetya Adi YF. Ayu PuspaDewi Lolang
Program:
int a=2;
int b=3;
int c=4;
int d=6;
int dp=5;
int e=7;
int f=8;
int g=9;
int btn1=13;
int btn2=12;
int counter=0;
int buttonUpState=0;
int lastButtonUpState=0;
int buttonDownState=0;
int lastButtonDownState=0;
void setup()
{
Serial.begin(9600);
pinMode(a,OUTPUT);
pinMode(b,OUTPUT);
pinMode(c,OUTPUT);
pinMode(d,OUTPUT);
pinMode(e,OUTPUT);
pinMode(f,OUTPUT);
pinMode(g,OUTPUT);
pinMode(dp,OUTPUT);
digitalWrite(dp,HIGH);
}
void loop()
{
buttonUpState=digitalRead(btn1);
buttonDownState=digitalRead(btn2);
if(buttonUpState!=lastButtonUpState)
{
if(buttonUpState==HIGH)
{
if(counter==9)
{
counter=-1;
}
counter++;
Serial.println(counter);
changeNumber(counter);
delay(300);
}
else
{
Serial.println("OFF");
}
delay(50);
}
if(buttonDownState!=lastButtonDownState)
{
if(buttonDownState==HIGH)
{
if(counter == 0)
{
counter = 10;
}
counter--;
Serial.println(counter);
changeNumber(counter);
delay(300);
}
else
{
Serial.println("OFF");
}
delay(50);
}
changeNumber(counter);
}
void changeNumber(int buttonPress)
{
switch (buttonPress)
{
//number 0
case 0:
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,HIGH);
break;
//number 1
case 1:
digitalWrite(a,HIGH);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
break;
//number 2
case 2:
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,HIGH);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,HIGH);
digitalWrite(g,LOW);
break;
//number 3
case 3:
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,LOW);
break;
//number 4
case 4:
digitalWrite(a,HIGH);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
break;
//number 5
case 5:
digitalWrite(a,LOW);
digitalWrite(b,HIGH);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,HIGH);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
break;
//number 6
case 6:
digitalWrite(a,LOW);
digitalWrite(b,HIGH);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
break;
//number 7
case 7:
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
break;
//number 8
case 8:
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
break;
//number 9
case 9:
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,HIGH);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
break;
}
}
int b=3;
int c=4;
int d=6;
int dp=5;
int e=7;
int f=8;
int g=9;
int btn1=13;
int btn2=12;
int counter=0;
int buttonUpState=0;
int lastButtonUpState=0;
int buttonDownState=0;
int lastButtonDownState=0;
void setup()
{
Serial.begin(9600);
pinMode(a,OUTPUT);
pinMode(b,OUTPUT);
pinMode(c,OUTPUT);
pinMode(d,OUTPUT);
pinMode(e,OUTPUT);
pinMode(f,OUTPUT);
pinMode(g,OUTPUT);
pinMode(dp,OUTPUT);
digitalWrite(dp,HIGH);
}
void loop()
{
buttonUpState=digitalRead(btn1);
buttonDownState=digitalRead(btn2);
if(buttonUpState!=lastButtonUpState)
{
if(buttonUpState==HIGH)
{
if(counter==9)
{
counter=-1;
}
counter++;
Serial.println(counter);
changeNumber(counter);
delay(300);
}
else
{
Serial.println("OFF");
}
delay(50);
}
if(buttonDownState!=lastButtonDownState)
{
if(buttonDownState==HIGH)
{
if(counter == 0)
{
counter = 10;
}
counter--;
Serial.println(counter);
changeNumber(counter);
delay(300);
}
else
{
Serial.println("OFF");
}
delay(50);
}
changeNumber(counter);
}
void changeNumber(int buttonPress)
{
switch (buttonPress)
{
//number 0
case 0:
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,HIGH);
break;
//number 1
case 1:
digitalWrite(a,HIGH);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
break;
//number 2
case 2:
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,HIGH);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,HIGH);
digitalWrite(g,LOW);
break;
//number 3
case 3:
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,LOW);
break;
//number 4
case 4:
digitalWrite(a,HIGH);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
break;
//number 5
case 5:
digitalWrite(a,LOW);
digitalWrite(b,HIGH);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,HIGH);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
break;
//number 6
case 6:
digitalWrite(a,LOW);
digitalWrite(b,HIGH);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
break;
//number 7
case 7:
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
break;
//number 8
case 8:
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
break;
//number 9
case 9:
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,HIGH);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
break;
}
}
7. Sebelum diupload, pastikan port yang tersambung adalah selain port COM1.
8. Lalu upload program tersebut.
VI. KESELAMATAN KERJA
1. Menggunakan workpack
2. Menggunakan topi
3. Jangan meletakkan arduino pada besi.
3. Jangan meletakkan arduino pada besi.
VII. KESIMPULAN
Dalam praktek kali ini siswa dapat membuat program 7 segment dan dapat merangkainya di protoboard, sehingga program dan rangkaian dapat berjalan dengan baik.
Mengetahui, Klaten, 8 Februari 2017
Pembimbing Peserta Didik
Komentar
Posting Komentar