CODINGAN ARDUINO
Digital Coding
void setup() {
// put your setup code here, to run once:
pinMode (2,OUTPUT);
pinMode (3,OUTPUT);
pinMode (4,OUTPUT);
pinMode (5,OUTPUT);
void loop() {
// put your main code here, to run repeatedly:
digitalWrite (2, HIGH);
digitalWrite (5, HIGH);
digitalWrite (3, LOW);
digitalWrite (4, LOW);
delay(250);
digitalWrite (2, LOW);
digitalWrite (5, LOW);
delay(100);
digitalWrite (2, HIGH);
digitalWrite (5, HIGH);
digitalWrite (3, LOW);
digitalWrite (4, LOW);
delay(250);
digitalWrite (2, LOW);
digitalWrite (5, LOW);
delay(100);
digitalWrite (2, HIGH);
digitalWrite (5, HIGH);
digitalWrite (3, LOW);
digitalWrite (4, LOW);
delay(250);
digitalWrite (2, LOW);
digitalWrite (5, LOW);
delay(100);
digitalWrite (2, HIGH);
digitalWrite (5, HIGH);
digitalWrite (3, LOW);
digitalWrite (4, LOW);
delay(300);
digitalWrite (2, LOW);
digitalWrite (5, LOW);
delay(150);
digitalWrite (2, HIGH);
digitalWrite (5, HIGH);
digitalWrite (3, LOW);
digitalWrite (4, LOW);
delay(300);
digitalWrite (2, LOW);
digitalWrite (5, LOW);
delay(150);
digitalWrite (3, HIGH);
digitalWrite (5, HIGH);
digitalWrite (2, LOW);
digitalWrite (4, LOW);
delay(700);
digitalWrite (3, LOW);
digitalWrite (5, LOW);
delay(200);
digitalWrite (3, HIGH);
digitalWrite (5, HIGH);
digitalWrite (2, LOW);
digitalWrite (4, LOW);
delay(700);
digitalWrite (3, LOW);
digitalWrite (5, LOW);
delay(200);
digitalWrite (3, HIGH);
digitalWrite (5, HIGH);
digitalWrite (2, LOW);
digitalWrite (4, LOW);
delay(700);
digitalWrite (3, LOW);
digitalWrite (5, LOW);
delay(200);
digitalWrite (3, HIGH);
digitalWrite (5, HIGH);
digitalWrite (2, LOW);
digitalWrite (4, LOW);
delay(1000);
digitalWrite (3, LOW);
digitalWrite (5, LOW);
delay(250);
digitalWrite (3, HIGH);
digitalWrite (5, HIGH);
digitalWrite (2, LOW);
digitalWrite (4, LOW);
delay(1000);
digitalWrite (3, LOW);
digitalWrite (5, LOW);
delay(250);
digitalWrite (4, HIGH);
digitalWrite (5, HIGH);
digitalWrite (2, LOW);
digitalWrite (3, LOW);
delay(1500);
digitalWrite (4, LOW);
digitalWrite (5, LOW);
delay(300);
digitalWrite (4, HIGH);
digitalWrite (5, HIGH);
digitalWrite (2, LOW);
digitalWrite (3, LOW);
delay(1500);
digitalWrite (4, LOW);
digitalWrite (5, LOW);
delay(300);
digitalWrite (4, HIGH);
digitalWrite (5, HIGH);
digitalWrite (2, HIGH);
digitalWrite (3, HIGH);
delay(70000);
}
Analog Coding
int pinLed1 = 2;
int pinLed2 = 3;
int pinLed3 = 4;
int pinPot = A0;
int buzzer = 5;
void setup() {
Serial.begin(9600);
pinMode(pinLed1, OUTPUT);
pinMode(pinLed2, OUTPUT);
pinMode(pinLed3, OUTPUT);
pinMode (pinPot, INPUT);
pinMode (buzzer, OUTPUT);
void loop() {
int nilaiPot = analogRead(pinPot);
Serial.println(nilaiPot);
if (nilaiPot > 0) {
digitalWrite(pinLed1, HIGH);
} else {
digitalWrite(pinLed1, LOW);
if (nilaiPot > 200) {
digitalWrite(pinLed2, HIGH);
} else {
digitalWrite(pinLed2, LOW);
}
if (nilaiPot > 400) {
digitalWrite(pinLed3, HIGH);
digitalWrite(buzzer, HIGH);
delay (100);
digitalWrite(buzzer, LOW);
delay (100);
} else {
digitalWrite(pinLed3, LOW);