Professional Documents
Culture Documents
B. Langkah kerja :
1. Buat rangkaian sebagai berikut menggunakan protoboard
int sensorPin = A0; // select the input pin for the potentiometer
int ledPin = 13;
// select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
// declare the ledPin as an OUTPUT:
pinMode(ledPin, OUTPUT);
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
digitalWrite(ledPin, HIGH);
// stop the program for <sensorValue> milliseconds:
delay(sensorValue);
// turn the ledPin off:
digitalWrite(ledPin, LOW);
// stop the program for for <sensorValue> milliseconds:
delay(sensorValue);
}
C. Tugas
Edit program contoh agar perubahan LED berkebalikan dengan contoh.
2.
Gambar 4.2 Rangkaian LCD
lcd.print(sensorValue);
// turn the ledPin on
digitalWrite(ledPin, HIGH);
// stop the program for <sensorValue> milliseconds:
delay(sensorValue);
// turn the ledPin off:
digitalWrite(ledPin, LOW);
// stop the program for for <sensorValue> milliseconds:
delay(sensorValue);
}
4. Compile dan upload program, lihat hasil yang terjadi pada LCD.
B. Tugas
1. Buat program untuk menampilkan hasil input analog dan nilai pengolahan dengan rumus
sebagai berikut :
Y = 0 jika x < 100;
Y = 0.5x jika 100 <= x <=500;
Y = 250 jika x > 500