const int analogInPin = 2; // Analog input pin that the potentiometer is attached to
const int analogOutPin = 25; // Analog output pin that the LED is attached to
int ref = 0, limite = 500;
int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to the PWM (analog out)
void setup() {
Serial.begin(9600); //inicializa a comunicação do Monitor Serial
pinMode(analogInPin, INPUT);
pinMode(analogOutPin, INPUT);
}
void loop() {
if(millis() - ref >= limite){
ref = millis();
sensorValue = analogRead(analogInPin); //lê o pino de forma analógica
outputValue = map(sensorValue, 0, 4095, 0, 255); //faz regra de três entre duas faixas de valores
analogWrite(analogOutPin, outputValue); //joga o resultado da regra de 3 no pino do LED
Serial.print("sensor = ");
Serial.print(sensorValue);
Serial.print("\t output = ");
Serial.println(outputValue);
}
}