]> git.piffa.net Git - sketchbook_andrea/blob - basic/pwm/pwm_4_analog_input/pwm_4_analog_input.ino
operatori + analog
[sketchbook_andrea] / basic / pwm / pwm_4_analog_input / pwm_4_analog_input.ino
1 /*
2   Analog PWM
3   
4   Impostare la frequenza del PWM tramite un input analogico.
5   
6   */
7   
8 int inputPin = A0;  // set input pin for the potentiometer
9 int inputValue = 0; // potentiometer input variable
10 int ledPin = 3;     // output pin, deve avere il PWM
11
12 void setup() {
13      // declare the ledPin as an OUTPUT:
14      pinMode(ledPin, OUTPUT);
15 }
16
17 void loop() {
18      // read the value from the potentiometer:
19      inputValue = analogRead(inputPin);
20
21      // send the square wave signal to the LED:
22      analogWrite(ledPin, inputValue/4); 
23      // la lettura analogica e' a 10 bit (0-1024)
24      // Il PWM invece e' a 8 bit (0-255)
25      // Circa 1024 / 4 ~= 255
26      
27      // Domanda: dovrebbe esserci un delay()?
28 }
29