Skip to content

Instantly share code, notes, and snippets.

@alepez
Last active December 19, 2015 18:39
Show Gist options
  • Save alepez/6000398 to your computer and use it in GitHub Desktop.
Save alepez/6000398 to your computer and use it in GitHub Desktop.
// imposta il numero del pin associato al led
int ledPin = 9;
// tiene in memoria il valore
int valore = 0;
void setup() {
// imposta il pin in modalita' OUTPUT
pinMode(ledPin, OUTPUT);
}
void loop() {
// imposta il pin al valore definito
analogWrite(ledPin, valore);
// aumenta di 1 il valore
valore++;
// aspetta 50 millisecondi
delay(50);
// se valore ha raggiunto il massimo lo rimette a 0
if (valore == 256) {
valore = 0;
}
}
@alepez
Copy link
Author

alepez commented Jul 15, 2013

Esempio semplice semplice, per "dimmerare" un led usando il PWM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment