You are on page 1of 5

Nama : ARBI INDRAWAN

Nim : 41416120064
Tugas : Jawaban Forum 5 Robotika
TUGAS FORUM 5

1. Berikut ini merupakan komponen-komponen yang digunakan.

2. Gambar Skema Rangkaian


3. Proses Pengujian Rangkaian dan Program

4. Source Code Arduino

int tbl1 = 0; //Kondisi terkini tombol1


int tbl2 = 0; //Kondisi terkini tombol2
int tbl3 = 0; //Kondisi terkini tombol3
int hitunganTombol1 = 0; // penghitung jumlah tombol 1 ditekan
int hitunganTombol2 = 0; // penghitung jumlah tombol 2 ditekan
int hitunganTombol3 = 0; // penghitung jumlah tombol 3 ditekan

int nilaiTerakhirTbl1 = 0; // nilai tombol 1 sebelumnya


int nilaiTerakhirTbl2 = 0; // nilai tombol 2 sebelumnya
int nilaiTerakhirTbl3 = 0; // nilai tombol 3 sebelumnya

void setup()
{

pinMode(8, OUTPUT); //LED


pinMode(9, OUTPUT); //LED
pinMode(10, OUTPUT); //LED
pinMode(11, OUTPUT); //LED
pinMode(12, OUTPUT); //LED
pinMode(13, OUTPUT); //LED

pinMode(2, INPUT); //Tombol 3


pinMode(3, INPUT); //Tombol 2
pinMode(4, INPUT); //Tombol 1
Serial.begin(9600);
}

void reset(){
pinMode(8, LOW); //LED
pinMode(9, LOW); //LED
pinMode(10, LOW); //LED
pinMode(11, LOW); //LED
pinMode(12, LOW); //LED
pinMode(13, LOW); //LED

void loop()
{

tbl1 = digitalRead(4);
tbl2 = digitalRead(3);
tbl3 = digitalRead(2);

// compare the buttonState to its previous state


if (tbl1 != nilaiTerakhirTbl1 || tbl2 != nilaiTerakhirTbl2 || tbl3 != nilaiTerakhirTbl3) {
// if the state has changed, increment the counter
if (tbl1 == HIGH) {
// if the current state is HIGH then the button
// wend from off to on:
hitunganTombol2 = 0;
hitunganTombol3 = 0;
hitunganTombol1++;

Serial.print("number of button 1 pushes: ");


Serial.println(hitunganTombol1);
Serial.print("number of button 2 pushes: ");
Serial.println(hitunganTombol2);
Serial.print("number of button 3 pushes: ");
Serial.println(hitunganTombol3);
Serial.println(" ");

if (tbl2 == HIGH) {
// if the current state is HIGH then the button
// wend from off to on:
hitunganTombol1 = 0;
hitunganTombol3 = 0;
hitunganTombol2++;

Serial.print("number of button 1 pushes: ");


Serial.println(hitunganTombol1);
Serial.print("number of button 2 pushes: ");
Serial.println(hitunganTombol2);
Serial.print("number of button 3 pushes: ");
Serial.println(hitunganTombol3);
Serial.println(" ");

if (tbl3 == HIGH) {
// if the current state is HIGH then the button
// wend from off to on:
hitunganTombol2 = 0;
hitunganTombol1 = 0;
hitunganTombol3++;

Serial.print("number of button 1 pushes: ");


Serial.println(hitunganTombol1);
Serial.print("number of button 2 pushes: ");
Serial.println(hitunganTombol2);
Serial.print("number of button 3 pushes: ");
Serial.println(hitunganTombol3);
Serial.println(" ");

// Delay a little bit to avoid bouncing


delay(50);
}
// save the current state as the last state,
//for next time through the loop
nilaiTerakhirTbl1 = tbl1;
nilaiTerakhirTbl2 = tbl2;
nilaiTerakhirTbl3 = tbl3;

if (nilaiTerakhirTbl1==HIGH) {
reset();
if (hitunganTombol1==0){
digitalWrite(13, LOW);
digitalWrite(12, LOW);
}
else if (hitunganTombol1 % 2 == 0) {
digitalWrite(13, LOW);
digitalWrite(12, HIGH);
}
else {
digitalWrite(13, HIGH);
digitalWrite(12, LOW);
}
}

if (nilaiTerakhirTbl2==HIGH) {
reset();
if (hitunganTombol2==0){
digitalWrite(11, LOW);
digitalWrite(10, LOW);
}
else if (hitunganTombol2 % 2 == 0) {
digitalWrite(11, LOW);
digitalWrite(10, HIGH);
}
else {
digitalWrite(11, HIGH);
digitalWrite(10, LOW);
}
}
if (nilaiTerakhirTbl3==HIGH) {
reset();
if (hitunganTombol3==0){
digitalWrite(9, LOW);
digitalWrite(8, LOW);
}
else if (hitunganTombol3 % 2 == 0) {
digitalWrite(9, LOW);
digitalWrite(8, HIGH);
}
else {
digitalWrite(9, HIGH);
digitalWrite(8, LOW);
}
}
}

You might also like