#define in12
#define in11
byte pot = A0;
byte motor = 9;
int nilai;
int output;
void setup()
{
pinMode(motor, OUTPUT);
pinMode(in12,OUTPUT);
pinMode(in11,OUTPUT);
Serial.begin(9600); //Set baud rate 9600
}
void loop() {
nilai = analogRead(pot);
output = map(nilai, 0, 1023, 0, 255);
analogWrite(motor, output);
digitalWrite(in12,HIGH);
digitalwrite(in11,LOW);
Serial.print("potensiometer: ");
Serial.print(nilai);
Serial.print(" ");
Serial.print("output: ");
Serial.print(output);
delay(2);
}
#define in11
byte pot = A0;
byte motor = 9;
int nilai;
int output;
void setup()
{
pinMode(motor, OUTPUT);
pinMode(in12,OUTPUT);
pinMode(in11,OUTPUT);
Serial.begin(9600); //Set baud rate 9600
}
void loop() {
nilai = analogRead(pot);
output = map(nilai, 0, 1023, 0, 255);
analogWrite(motor, output);
digitalWrite(in12,HIGH);
digitalwrite(in11,LOW);
Serial.print("potensiometer: ");
Serial.print(nilai);
Serial.print(" ");
Serial.print("output: ");
Serial.print(output);
delay(2);
}
5. Analisa [kembali]
Mengubah fungsi potensiometer, yang awalnya nilai maksimum potensiometer akan mempercepat motor menjadi memperlembat motor DC
- kode 1
#define in12
#define in11
byte pot = A0;
byte motor = 9;
int nilai;
int output;
void setup()
{
pinMode(motor, OUTPUT);
pinMode(in12,OUTPUT);
pinMode(in11,OUTPUT);
Serial.begin(9600);
}
void loop() {
nilai = analogRead(pot);
output = map(nilai, 0, 1023, 0, 255);
analogWrite(motor, output);
digitalWrite(in12,LOW);
digitalwrite(in11,HIGH);
Serial.print("potensiometer: ");
Serial.print(nilai);
Serial.print(" ");
Serial.print("output: ");
Serial.print(output);
delay(2);
}
- kode 2
#define in12
#define in11
byte pot = A0;
byte motor = 9;
int nilai;
int output;
void setup()
{
pinMode(motor, OUTPUT);
pinMode(in12,OUTPUT);
pinMode(in11,OUTPUT);
Serial.begin(9600); //Set baud rate 9600
}
void loop() {
nilai = analogRead(pot);
output = map(nilai, 0, 1023, 255, 0 );
analogWrite(motor, output);
digitalWrite(in11,HIGH);
digitalwrite(in12,LOW);
Serial.print("potensiometer: ");
Serial.print(nilai);
Serial.print(" ");
Serial.print("output: ");
Serial.print(output);
delay(2);
}
#define in11
byte pot = A0;
byte motor = 9;
int nilai;
int output;
void setup()
{
pinMode(motor, OUTPUT);
pinMode(in12,OUTPUT);
pinMode(in11,OUTPUT);
Serial.begin(9600); //Set baud rate 9600
}
void loop() {
nilai = analogRead(pot);
output = map(nilai, 0, 1023, 255, 0 );
analogWrite(motor, output);
digitalWrite(in11,HIGH);
digitalwrite(in12,LOW);
Serial.print("potensiometer: ");
Serial.print(nilai);
Serial.print(" ");
Serial.print("output: ");
Serial.print(output);
delay(2);
}
Caranya pada koding 1, nilai high dan low dari pin di ganti menjadi terbalik, sehingga inputan potensiometer pun terbalik. Sedangkan pada koding 2 hanya inputan pin potensiometer diganti letaknya saja sehingga nilai maksimum akan berganti menjadi nilai minimum, begitupun sebaliknya.
Tidak ada komentar:
Posting Komentar