watching clock input for a simple drum machine

Status
Not open for further replies.

Oddball

Active member
I'm working on a simpler version of a Euclidean sequencer, eventually it's a variable divide down setup, based off the "blink without delay" example. what I want to do is watch an analog read pin, which will be fed a clock in or square wave etc. when it crosses a threshold (say 200 I'm not sure yet what I'm going to use) it records millis, and then on the next threshold crossing, it then records a second millis, subtracts the two, and returns a value. What I need to prevent is it measuring millis on the same event, so I need to throw a minimum millis value in as well. I've kinda worked myself up, but this is a copy of code when i decided to throw up the white flag lol

to sum it up all I'm trying to do is measure between two events around the 200-1000 millisecond range on a single analog input using arduino IDE, with a teensy 4.0. also I want to keep the analog input, as I might want to add an adjustment for the offset later.

Code:
sync = analogRead(8);

   if (sync > 200) { 
    syncMillisStart  = millis(); // 2000 
      }
  else {
    syncMillisStop = millis(); // 1000
  }


  if (sync > 200 && (syncMillisStart - syncMillisStop > 1000) {
    syncMillisStop = millis();
    
  }

  freq = syncMillisStart - syncMillisStop
 
Status
Not open for further replies.
Back
Top