running led

gambar raning led

https://www.instructables.com/LEDS-With-a-Potentiometer/


code program 1


// Lampu LED Berjalan Menggunakan Arduino UNO
// Menyalakan LED dengan Aktif HIGH
 
int ledPin1 = 0;
int ledPin2 = 1;
int ledPin3 = 2;
int ledPin4 = 3;
int ledPin5 = 4;
// type data yang berfungsi sebagai penyimpan bilangan bulat
 
void setup() 
{
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
// menjadikan PIN 0, 1, 2, 3, dan 4 sebagai OUTPUT
}
 
void loop()
// Menyalakan LED sacara bergilir 
{
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, LOW);
digitalWrite(ledPin5, LOW);
delay(1000);
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, LOW);
digitalWrite(ledPin5, LOW);
delay(1000);
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, HIGH);
digitalWrite(ledPin4, LOW);
digitalWrite(ledPin5, LOW);
delay(1000);
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, HIGH);
digitalWrite(ledPin5, LOW);
delay(1000);
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, LOW);
digitalWrite(ledPin5, HIGH);
delay(1000);
}





code program 3

 

// LED Intermitente c/ Potenciómetro
// Miguel Dias - ESGC 2018
 
const int Potenciometro = A0;
const int Led = 10;
int ValorPoten = 0;
 
void setup() {
pinMode(Led, OUTPUT);
}
 
void loop() {
ValorPoten = analogRead(Potenciometro);
digitalWrite(Led, HIGH);
delay(ValorPoten);
digitalWrite(Led, LOW);
delay(ValorPoten);
}

code program 4

// Lampu LED Berjalan Menggunakan Arduino UNO
// Menyalakan LED dengan Aktif HIGH
 
void setup() 
{
pinMode(0, OUTPUT);
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
// menjadikan PIN 0, 1, 2, 3, dan 4 sebagai OUTPUT
}
 
void loop() 
{
//menyala secara bergilir
 
digitalWrite(0, HIGH);
digitalWrite(1, LOW);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
delay(1000);
digitalWrite(0, LOW);
digitalWrite(1, HIGH);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
delay(1000);
digitalWrite(0, LOW);
digitalWrite(1, LOW);
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
delay(1000);
digitalWrite(0, LOW);
digitalWrite(1, LOW);
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
delay(1000);
digitalWrite(0, LOW);
digitalWrite(1, LOW);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
delay(1000);
}


code 5

/*
  Blink LED with POT
 Demonstrates analog input by reading an analog sensor on analog pin 0 and
 turning on and off a light emitting diode(LED)  connected to digital pin 13. 
 The amount of time the LED will be on and off depends on
 the value obtained by analogRead(). 
 
 The circuit:
 * Potentiometer attached to analog input 0
 * center pin of the potentiometer to the analog pin
 * one side pin (either one) to ground
 * the other side pin to +5V
 * LED anode (long leg) attached to digital output 13
 * LED cathode (short leg) attached to ground
 
 * Note: because most Arduinos have a built-in LED attached 
 to pin 13 on the board, the LED is optional.
 
 */
int sensorPin = A0;    // select the input pin for the potentiometer
int LED1 = 8;
int LED2 = 9;
int LED3 = 10;

int sensorValue = 0;  // variable to store the value coming from the sensor
void setup() {
  // declare the ledPin as an OUTPUT:
 pinMode(LED1, OUTPUT);
 pinMode(LED2, OUTPUT);
 pinMode(LED3, OUTPUT);
 pinMode(A0, INPUT);

}
void loop() {
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);    
  
  // turn the ledPin on
 digitalWrite(LED1, HIGH);
  // stop the program for <sensorValue> milliseconds:
      
  // turn the ledPin off:        
  digitalWrite(LED2, LOW);   
  // stop the program for for <sensorValue> milliseconds: di dalam
 
  digitalWrite(LED3, LOW);
  // stop the program for <sensorValue> milliseconds:
  delay(sensorValue);          
  
  // turn the ledPin off:        
  digitalWrite(LED1, LOW);   
  // stop the program for for <sensorValue> milliseconds:
 
  digitalWrite(LED2, HIGH);
  // stop the program for <sensorValue> milliseconds:
   
  // turn the ledPin off:        
  digitalWrite(LED3, LOW);   
  // stop the program for for <sensorValue> milliseconds: 
    delay(sensorValue);         

   // turn the ledPin off:        
  digitalWrite(LED1, LOW);   
  // stop the program for for <sensorValue> milliseconds:
 
  digitalWrite(LED2, LOW);
  // stop the program for <sensorValue> milliseconds:
   
  // turn the ledPin off:        
  digitalWrite(LED3, HIGH);   
  // stop the program for for <sensorValue> milliseconds: 
    delay(sensorValue);  
}

Komentar

Postingan populer dari blog ini

jam digital

3 phase