Oleh :
Teguh Setiawan Iskandar
C010317099
Listrik-3D3K
Dari gambar sistem di atas, buatlah program sehingga jika b1 ditekan akan
menyebabkan display 7-segment cuonting-UP, jika b2 ditekan maka counting akan
berhenti, jika b3 ditekan maka display 7-segment akan counting DOWN.
JAWABAN
Soal no. 1
1. sistem yang diminta adalah seperti gambar di bawah.
2. program untuk menapilkan huruf nama pendek berjalan dengan satu tombol untuk
mem-pause tuisan dan menjalankanya kembali adalah sebagai berikut.
Program 1
char huruf[] = {0xff, 0xff, 0xff, 0xff, 0xff,
0x3f, 0x3f, 0x80, 0x3f, 0x3f, 0xff,
0x80, 0x36, 0x36, 0x36, 0x3e, 0xff,
0x41, 0x3e, 0x36, 0x36, 0x30, 0xff,
0x81, 0x7e, 0x7e, 0x7e, 0x81, 0xff,
0x80, 0x77, 0x77, 0x77, 0x80, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff,
};
char led = 1, i = 0, j, geser;
bool b1, b1Old, tunda=0;
void setup() {
// put your setup code here, to run once:
DDRD = 0xFF;
DDRB = 0xFF;
pinMode(14, INPUT_PULLUP);
}
void loop() {
// put your main code here, to run repeatedly:
b1Old=b1;
b1 = not digitalRead(14);
if(b1 and not b1Old) tunda= not tunda;
PORTB = (led << i);
PORTD = huruf[i + geser];
delay(2.8);
i++;
if (i == 5)
{
i = 0;
if (tunda) j = 0;
else j++;
if (j == 10)
{
j = 0;
geser++;
{
if (geser > 35)
geser = 0;
}
}
}
}
Soal no.2
Program untuk menampilkanjika b1 ditekan akan menyebabkan display 7-segment
cuonting-UP, jika b2 ditekan maka counting akan berhenti, jika b3 ditekan maka
display 7-segment akan counting DOWN adalah sebagai berikut.
Program 2
char bil[] = {0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x90};
unsigned char i = 0, j = 0, digit, satuan, puluhan, detik = 0;
bool b1, b2, b3, b4, b1Old, b2Old, b3Old, b4Old, naik, turun;
byte kananPins[] = {6, 5, 4, 3, 2, 0, 1};
byte kiriPins[] = {13, 12, 11, 10, 9, 8, 7};
void setup() {
// put your setup code here, to run once:
pinMode (14, INPUT_PULLUP);
pinMode (15, INPUT_PULLUP);
pinMode (16, INPUT_PULLUP);
DDRD = 0xFF;
DDRB = 0xFF;
PORTB = 0XFF;
PORTD = 0XFF;
}
void loop() {
// put your main code here, to run repeatedly:
b1Old = b1;
b2Old = b2;
b3Old = b3;
b1 = not digitalRead(14);
b2 = not digitalRead(15);
b3 = not digitalRead(16);
if (b1 and not b1Old) naik = 1, turun = 0;
if (b2 and not b2Old) naik = 0, turun = 0;
if (b3 and not b3Old) turun = 1, naik = 0;