A seguinte biblioteca me da o exemplo para piscar o led a cada 0.1 segundo.
#include <TimerOne.h>
void setup()
{
// Initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards
pinMode(13, OUTPUT);
Timer1.initialize(100000); // set a timer of length 100000 microseconds (or 0.1 sec - or 10Hz => the led will blink 5 times, 5 cycles of on-and-off, per second)
Timer1.attachInterrupt( timerIsr ); // attach the service routine here
}
void loop()
{
// Main code loop
// TODO: Put your regular (non-ISR) logic here
}
/// --------------------------
/// Custom ISR Timer Routine
/// --------------------------
void timerIsr()
{
// Toggle LED
digitalWrite( 13, digitalRead( 13 ) ^ 1 );
}
Porem o valor do tempo está fixo no setup . Como eu teria que fazer para alterar via um potenciometro?
Pedir ajuda nao tem mal algum... e para isso, e lavar roupa suja por vezes, que o forum serve.
O que eu aconselho a fazeres para nao sentires isso e procurares por informacao. Eu nunca tinha visto essa biblioteca na minha vida. em menos de 5 minutos encontrei a pagina oficial da biblioteca com toda a documentacao sobre como fazer o que pretendes.
Certamente que tu estiveste na mesma pagina para fazer download, podias ter visto isto la...
O que tu pretendes e o metodo setPeriod().
loop(){
unsigned int valor = analogRead(pino_AD);
timer1.setPeriod(valor);
}