Tp 1 : Percobaan 6 Kondisi 4
1. Prosedur [Kembali]
2. Tulis program untuk arduino di software Arduino IDE.
3. Compile program tadi, lalu upload ke dalam arduino.
4. Setelah program selesai di upload, jalankan simulasi rangkaian pada proteus.
Flowchart :
Listing Program :
#define A 8
#define B 9
#define C 10
#define D 11
#define PB1 2
#define PB2 3
#define PB3 4
#define PB4 5
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(A, OUTPUT);
pinMode(B, OUTPUT);
pinMode(C, OUTPUT);
pinMode(D, OUTPUT);
pinMode(PB1, INPUT_PULLUP);
pinMode(PB2, INPUT_PULLUP);
pinMode(PB3, INPUT_PULLUP);
pinMode(PB4, INPUT_PULLUP);
}
void pergerakan_1(){
digitalWrite(A,0);
digitalWrite(D,1);
digitalWrite(B,0);
digitalWrite(C,1);
}
void pergerakan_2(){
digitalWrite(A,1);
digitalWrite(D,1);
digitalWrite(B,0);
digitalWrite(C,0);
}
void pergerakan_3(){
digitalWrite(A,1);
digitalWrite(D,0);
digitalWrite(B,1);
digitalWrite(C,0);
}
void pergerakan_4(){
digitalWrite(A,0);
digitalWrite(D,0);
digitalWrite(B,1);
digitalWrite(C,1);
}
void nonpergerakan(){
digitalWrite(A,0);
digitalWrite(D,0);
digitalWrite(B,0);
digitalWrite(C,0);
}
void loop() {
int b4 = digitalRead(PB4);
int b3 = digitalRead(PB3);
int b2 = digitalRead(PB2);
int b1 = digitalRead(PB1);
if (b4 == LOW) {
pergerakan_4(); // Pindahkan servo ke 45 derajat
}
else if (b3 == LOW) {
pergerakan_3(); // Pindahkan servo ke 45 derajat
}
else if (b2 == LOW) {
pergerakan_2(); // Pindahkan servo ke 45 derajat
}
else if (b1 == LOW) {
pergerakan_1(); // Pindahkan servo ke 45 derajat
}
else {
nonpergerakan();
delay(100);
}
}
Video Percobaan klik disini
Tidak ada komentar:
Posting Komentar