A time to log how long an event goes for

Ive got a round drum, with 4 equally spaced, equal delay teeth on it. Using a optical sensor to detect its state. Think of it as a RPM sensor.

This drum will be moving about 1500rpm MAX. I want to record how long the sensor is digitally HIGH for, and how long its LOW for. If the drum is accelerating, it should get shorter and shorter timed states. Steady state they should be fairly much identical, and drum slowing down the timed event should be getting longer.

I want those 2 numbers to be Serial.print'd together, with a ',' between them. This loops 10x and then stops. Just a quick "data collection" for what im using it for.
it SHOULD spit out data like:

123,121
120,119
117,114
110,101

I hope someone understands what im trying to achieve.

Heres a snip of code ive written for this purpose. It does indeed compile, BUT ! ive NOT UPLOADED TO MY AVR YET. Something about it just isnt right.

void Gear_Ratio() {
            for(int x = 0; x < 10; x++) // loop this function set 10x, thats what the frontend wants
            
            {
            if (digitalRead(Drum_HiLo) == HIGH)
            {
              int sample1 = 0;
                sample1 = micros(); // record the length in microsec that pin is HIGH
               Serial.println(sample1,',');
            }
            else
            {
              int sample2 = 0;
                sample2 = micros(); // record the length in microsec the pin is LOW
                Serial.print(sample2);
            }
      
        }

Anyone able to point me in the right direction ? Im not sure if i can use micros() in this manor.. Is it possible ?

Check the pulseIn() function

awesome. Cheers.
http://www.arduino.cc/en/Reference/PulseIn

Ill go forth and fix it after some sleep. Im too brain dead to code now. Been at it too long. Ill post my fix later on just for future reference for others.

Ive not uploaded this sketch to my AVR just yet. Id like to know if there is a more elegant way of doing a Serial.println with multi variables ?

Much like:

Serial.println((sample1),(","),(sample2);

Ive read both:

and not found anything which really answers my question. Only thing i could possibly try is do it all with Serial.print(); and then just do a Serial.print(""); for a carriage return ??

Heres my rewritten code.. All of 2mins work.. Be gentle please:

void Gear_Ratio() {
            for(int x = 0; x < 10; x++) // loop this function set 10x, thats what the frontend wants
            {
            sample1 = 0;  // Reset the sample time back to zero
            sample1 = pulseIn(Drum_HiLo, HIGH); // measure how long the tooth is on for, store it in "sample1"
            sample2 = 0; // Reset sample2 back to zero
            sample2 = pulseIn(Drum_HiLo, LOW); // measure how long the tooth is off for
            Serial.print(sample1);
            Serial.print(",");  //  Should print out "yyy,xxx" on 10 individual lines.
            Serial.println(sample2);
            }
        Ending_Run();
}

So yeah.. should i change the Serial.println(sample2); to:

Serial.print(sample2);
Serial.print("");

Will this loop properly for 10x as i hope ? or did i get some syntax wrong ? Anyone withh some suggestions would receive free cookies. Or beer if your old enough.

Id like to know if there is a more elegant way of doing a Serial.println with multi variables ?

Check - Streaming | Arduiniana