MsTimer2::set(500, flash); // 500ms period
MsTimer2::start();
}
void loop() {
}
The Program doesn't work on my arduino Mega 2560. The LED doesn't flash. But the "blink"-example works perfectly. I've downloaded the mstimer2.h-libary and copied it into the arduino libary-folder.
Does anybody know what I'm doing wrong ?
And what do you think how many times a analog-sensor can be read out per second using the mstimer-function ? And what happens if a command takes longer than the time specified in MsTimer::set(periodtime,....) ?
The Program doesn't work on my arduino Mega 2560. The LED doesn't flash. But the "blink"-example works perfectly. I've downloaded the mstimer2.h-libary and copied it into the arduino libary-folder.
Does anybody know what I'm doing wrong ?
What is connected to pin4? The onboard led called in the "blink" is attached to pin 13.
And what do you think how many times a analog-sensor can be read out per second using the mstimer-function ?And what happens if a command takes longer than the time specified in MsTimer::set(periodtime,....) ?
The standard analogRead() take about 110 microseconds.
The function executed at the time specified is an interrupt service routine (ISR). If execution of the ISR takes longer than the time to the next arriving interrupt, the new interrupt will be noted, and placed in a queue for execution when the running ISR is completed.
ISR's should be short and quick to run. The fact that you are asking the question indicates that you may have the wrong idea of what you want to do on a 500 ms timer interrupt.
/*
MsTimer2 is a small and very easy to use library to interface Timer2 with
humans. It's called MsTimer2 because it "hardcodes" a resolution of 1
millisecond on timer2
For Details see: http://www.arduino.cc/playground/Main/MsTimer2
*/
#include <MsTimer2.h>
// Switch on LED on and off each half second
#if ARDUINO >= 100
const int led_pin = LED_BUILTIN; // 1.0 built in LED pin var
#else
const int led_pin = 13; // default to pin 13
#endif
void flash()
{
static boolean output = HIGH;
digitalWrite(led_pin, output);
output = !output;
}
void setup()
{
pinMode(led_pin, OUTPUT);
MsTimer2::set(500, flash); // 500ms period
MsTimer2::start();
}
void loop()
{
}