Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Nama : Achmad Fikri Ajwadi

NIM : 2315374046
Tugas2

#include <Servo.h>

Servo myservo;
int pot1 = A0;
int pot2 = A1;
int led1 = 10;
int led2 = 11;
int val1 = 0;
int val2 = 0;
int MapPot1 = 0;
int MapPot2 = 0;

void setup() {
myservo.attach(9);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
myservo.write(90);
}

void loop() {
val1 = analogRead(pot1);
val2 = analogRead(pot2);
MapPot1 = map(val1, 0, 1023, 0, 90);
MapPot2 = map(val2, 0, 1023, 0, 90);
int sudut = MapPot1 + MapPot2 + 90;
if (MapPot1 > MapPot2) {
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
} else if (MapPot1 < MapPot2) {
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
} else {
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
}
myservo.write(sudut);
delay(15);
}

You might also like