lorenzo_cesaretti

Fading Led Arduino

Apr 12th, 2021 (edited)
580
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Esempio 11: Fading
  2. // LED collegato al pin digitale 11
  3. #define LED 11              
  4. int valoreFade = 0;         // variabile usata per contare in avanti e indietro
  5.  
  6. void setup()  {
  7.   pinMode(LED, OUTPUT);     // imposta il pin digitale come output
  8. }
  9.  
  10. void loop()  {
  11.   // procede ciclicamente da 0 a 254 (fade in -> aumento luminosità)
  12.   for (valoreFade = 0 ; valoreFade <255; valoreFade++)
  13.   {
  14.     analogWrite(LED, valoreFade);
  15.     delay(10);
  16.   }
  17.   delay(1000);
  18.   for (valoreFade = 255 ; valoreFade > 0; valoreFade--)
  19.   {
  20.     analogWrite(LED, valoreFade);      //impostiamo la luminosità del LED
  21.     delay(10);
  22.     // aspettiamo 10ms per percepire la viariazione di luminosità,
  23.     //perché analogWrite è istantaneo
  24.   }
  25. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×