Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
semsemharaz
Published

LED Blink and Fade with Arduino

This example shows the simplest thing you can do with an Arduino to see physical output: it blinks and fades the LED.

BeginnerProtip1,013
LED Blink and Fade with Arduino

Things used in this project

Story

Read more

Schematics

Schematic for the project

Code

LED Blink

C/C++
int led = 13;

//          
void setup() {

  pinMode(led, OUTPUT);  //  LED_BULTIN OUTPUT  
}

// 
void loop() {
  digitalWrite(led, HIGH);   // LED   (LED  HIGH)
  delay(1000);                       // 1 
  digitalWrite(led, LOW);    // LED  (LED  LOW)
  delay(1000);                       // 1 
}

LED Fade

C/C++
int led = 13;           // PWM( )  13 led  
int brightness = 0;    //   brightness 
int fadeAmount = 5;    // fade  


void setup() {
  // declare pin 13 to be an output: 13 OUTPUT 
  pinMode(led, OUTPUT);
}

// 
void loop() {
  //  led(13) 
  analogWrite(led, brightness);

  // brightness fadeAmount   
  brightness = brightness + fadeAmount;

  // brightness  0  255   fadeAmount  - 
  if (brightness <= 0 || brightness >= 255) {
    fadeAmount = -fadeAmount;
  }
  //  30 milli    
  delay(30);
}

Credits

semsemharaz
6 projects • 1 follower
Contact

Comments

Please log in or sign up to comment.