I'm using the Arduino sketch for LED stroboscope found here: http://mehax.blogspot.co.uk/2011/02/arduino-stroboscope.html.
Also below, I've inserted the loop part where this calculations are made:
void loop() {
// this while is a workaround for timer limitations using micros vs millis
sensorValue = analogRead(analogInPin); //take potentiometer reading
hold = sensorValue*55 + 400; //add some time to scale and for code execution
microsCurrent = micros(); // collect current time
if (microsCurrent > microsPrev + hold){ //set up timing loop
frequency = 1000000/(microsCurrent - microsPrev);
microsPrev = microsPrev + hold; //set up millis for delay stuff
//set all 6 LEDs high (they were already plugged in)
digitalWrite(3,HIGH);
digitalWrite(5,HIGH);
digitalWrite(6,HIGH);
digitalWrite(9,HIGH);
digitalWrite(10,HIGH);
digitalWrite(11,HIGH);
delayMicroseconds(.02*hold); //leave LEDs on long enough to see
//set all LEDs low
digitalWrite(3,LOW);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(9,LOW);
digitalWrite(10,LOW);
digitalWrite(11,LOW);
if(millis() > millisSerial + 200){
millisSerial=millis(); //reset timer
holdFrequency = 1000000/hold;
//do some math to find values
rpm = frequency * 60;
I want to use this code in my project, but I don't really understand how this code calculates the stobing frequency.
So, I have following questions:
- Why "hold" variable is calculated in the given way?
- Why "microsCurrent", "microsPrev" and all other timings are executed?
- How "frequency is calculated"?
- What is "hold frequency" variable?
Sorry, I'm very new to Arduino and don't know much coding. Will appreciate very much your help!