Monday, 31 August 2020

PWN and Transistors

W3: PWN and Transistors. Fades, Voltage Dividers:

Fades:

  • 1x Arduino or Genuino board
  • 1x LED
  • 1x Resistor 
  • 6x Jumpers
  • 1x Perfboard

Code: 

int led = 9;           // the PWM pin the LED is attached to
int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by

  pinMode(led, OUTPUT);
}


void loop() {

  analogWrite(led, brightness);


  brightness = brightness + fadeAmount;


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

No comments:

Post a Comment