MODUL 2 / TEORI KOMPONEN
01.491. Teori Komponen [kembali]
a. Arduinob. Switch
Terminal sentral (COM) akan terhubung ke salah satu terminal dan akan terputus ke terminal lainnnya dalam satu kondisi.
c. seven segment
d. Keypad
4. Listing Program [kembali]
#include < mega128.h > #include < delay.h > #includechar tombol[4][3] = { {'1', '2', '3'}, {'4', '5', '6'}, {'7', '8', '9'}, {'*', '0', '#'} }; byte pin[] = {2, 3, 4, 5, 6, 7, 8, 9}; int sakelar[] = {23, 25, 27, 29, 31, 33, 35, 37}; byte pinBaris[] = {17, 18, 19, 20}; byte pinKolom[] = {14, 15, 16}; Keypad keypad = Keypad(makeKeymap(tombol), pinBaris, pinKolom, 4, 3); void setup() { pinMode(10,OUTPUT); digitalWrite(10,LOW); for(int i=0;i<8 br="" i=""> { pinMode(sakelar[i],OUTPUT); } } void loop() { char kode = keypad.getKey(); if (kode == NO_KEY) return; if (kode == '*' || kode == '#') { return; } if(kode == '0') { digitalWrite(2,HIGH); digitalWrite(3,HIGH); digitalWrite(4,HIGH); digitalWrite(5,HIGH); digitalWrite(6,HIGH); digitalWrite(7,HIGH); digitalWrite(8,LOW); digitalWrite(9,LOW); } else if(kode == '1') { digitalWrite(2,LOW); digitalWrite(3,HIGH); digitalWrite(4,HIGH); digitalWrite(5,LOW); digitalWrite(6,LOW); digitalWrite(7,LOW); digitalWrite(8,LOW); digitalWrite(9,LOW); } else if(kode == '2') { digitalWrite(2,HIGH); digitalWrite(3,HIGH); digitalWrite(4,LOW); digitalWrite(5,HIGH); digitalWrite(6,HIGH); digitalWrite(7,LOW); digitalWrite(8,HIGH); digitalWrite(9,LOW); } else if(kode == '3') { digitalWrite(2,HIGH); digitalWrite(3,HIGH); digitalWrite(4,HIGH); digitalWrite(5,HIGH); digitalWrite(6,LOW); digitalWrite(7,LOW); digitalWrite(8,HIGH); digitalWrite(9,LOW); } else if(kode == '4') { digitalWrite(2,LOW); digitalWrite(3,HIGH); digitalWrite(4,HIGH); digitalWrite(5,LOW); digitalWrite(6,LOW); digitalWrite(7,HIGH); digitalWrite(8,HIGH); digitalWrite(9,LOW); } else if(kode == '5') { digitalWrite(2,HIGH); digitalWrite(3,LOW); digitalWrite(4,HIGH); digitalWrite(5,HIGH); digitalWrite(6,LOW); digitalWrite(7,HIGH); digitalWrite(8,HIGH); digitalWrite(9,LOW); } else if(kode == '6') { digitalWrite(2,HIGH); digitalWrite(3,LOW); digitalWrite(4,HIGH); digitalWrite(5,HIGH); digitalWrite(6,HIGH); digitalWrite(7,HIGH); digitalWrite(8,HIGH); digitalWrite(9,LOW); } else if(kode == '7') { digitalWrite(2,HIGH); digitalWrite(3,HIGH); digitalWrite(4,HIGH); digitalWrite(5,LOW); digitalWrite(6,LOW); digitalWrite(7,LOW); digitalWrite(8,LOW); digitalWrite(9,LOW); } else if(kode == '8') { digitalWrite(2,HIGH); digitalWrite(3,HIGH); digitalWrite(4,HIGH); digitalWrite(5,HIGH); digitalWrite(6,HIGH); digitalWrite(7,HIGH); digitalWrite(8,HIGH); digitalWrite(9,LOW); } else if(kode == '9') { digitalWrite(2,HIGH); digitalWrite(3,HIGH); digitalWrite(4,HIGH); digitalWrite(5,HIGH); digitalWrite(6,LOW); digitalWrite(7,HIGH); digitalWrite(8,HIGH); digitalWrite(9,LOW); } } 8>