How to make illusion of moving light with Arduino


If you want to make illusion of moving light then it is very easy to make it with Arduino. Just by turning on and off the leds for certain milliseconds, you can make the light flow like water.

Settings:
  digitalWrite(led1, HIGH);   // Turn the LED on
  delay(250);               // Wait for miliseconds. You can change this for any amount you want.
  digitalWrite(led1, LOW);    // Turn the LED off
  delay(1);               // wait for a milisecond. You can change this for any amount you want.


The sketch is in the box. 

int led1 = 3;
int led2 = 4;
int led3 = 5;
int led4 = 6;


// the setup routine runs once when you press reset:
void setup() {               
  // initialize the digital pin as an output.
  pinMode(led1, OUTPUT); 
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT); 
  pinMode(led4, OUTPUT);  
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led1, HIGH); 
  delay(250);             
  digitalWrite(led1, LOW);   
  delay(1);            
 
  digitalWrite(led2, HIGH); 
  delay(100);             
  digitalWrite(led2, LOW);  
  delay(1); 
 
  digitalWrite(led3, HIGH); 
  delay(100);             
  digitalWrite(led3, LOW);  
  delay(1);
 
  digitalWrite(led4, HIGH); 
  delay(275);             
  digitalWrite(led4, LOW);  
  delay(1);
 
  digitalWrite(led3, HIGH); 
  delay(50);             
  digitalWrite(led3, LOW);  
  delay(1);
 
  digitalWrite(led2, HIGH); 
  delay(50);             
  digitalWrite(led2, LOW);  
  delay(1);

}

Watch the video to see the sketch in action.  




No comments:

Post a Comment



Newly posted:
Reason why rich getting richer and poor getting poorer