Understanding TimerOne


hi,
i´m new programming , trying understand functions. have "read" voltage make led blink @ different speed according voltage input on a0. i´m trying same using timerone instead of "delay" cant work way want. input value (get_voltage) adjust blinking  is in setup want in loop. possible , code shall use? maybe "bool"?

regards
joakim

code: [select]


const unsigned int pot_read=0;
  const float supply_voltage=5.0;
  const unsigned int baud_rate=9600;
  #include "timerone.h"

void setup() {
 serial.begin(baud_rate);
 pinmode(9, output);
timer1.initialize(get_voltage()*50000);      
timer1.pwm(9,512);              
timer1.attachinterrupt(callback);  

}

void callback()
{
digitalwrite(10, digitalread(10) ^ 1);
}
 
 void loop() {
 serial.print(get_voltage());
serial.println(" volt");
delay(1000);


}

const float get_voltage(){
const int out_voltage=analogread(pot_read);
const float voltage=out_voltage*supply_voltage/1024;
return (voltage);
}


i not familiar timer1 library.

if not interested in using library can achieve want using millis() illustrated in several things @ time

...r


Arduino Forum > Using Arduino > Programming Questions > Understanding TimerOne


arduino

Comments