Button to reset clock on sequencer

I have a 16 step sequencer running from an external clock.
I added a button switch that is - normally open - When I tap the button, I'd like to reset the clock to step 1

my code is below
when the button is released/open the sequence does not move forward and holds at step1
When the restart clock button is held down the sequence moves forward

this is the opposite of what I want to do.

I've tried variations- some with the INPUT_PULLUP as an INPUT
and the setInputPulledUp() as setInput()
this didn't resolve the problem
at least the code I've pasted is so close.

I hope someone can help me to change that button behavior.
Bad button :-/

Thanks
TK

#define CLK_PIN 13
#define RESTART_CLK_PIN 11
//All switches use the Arduino input pullup resistors
  pinMode(ENCODER_SW_PIN, INPUT_PULLUP);
  pinMode(RESTART_CLK_PIN, INPUT_PULLUP);


 FastGPIO::Pin<ENCODER_SW_PIN>::setInputPulledUp(); //BUTTON
 FastGPIO::Pin<RESTART_CLK_PIN>::setInputPulledUp(); //Restart Clock Button
 FastGPIO::Pin<CLK_PIN>::setInput(); // CLK
//--------------External clock input detection, counting----------------

 clock_in = FastGPIO::Pin<CLK_PIN>::isInputHigh();

// // Reset clock to step_count=1
if (FastGPIO::Pin<RESTART_CLK_PIN>::isInputHigh()) {
  step_count = 1;
  refresh_display = true;
  last_refresh = millis();
}

 if (old_clock_in == 0 && clock_in == 1) {
   if((millis()-last_refresh)>max_refresh_time){
      refresh_display = true;
      last_refresh = millis();
   }
   step_count++;
 }

I have no idea which board / processor this is written for. Is there an isInputLow() ?

No, part of your code.
Post the full code so we don't have to play guessing games.

Where is your glasball ? :wink:

1 Like

Usually if a button does exactly the opposite to what you want, the fix is just that easy. Look for the other condition.

This code has some stuff going on, but that doesn't stop anyone.

Take

if (FastGPIO::Pin<RESTART_CLK_PIN>::isInputHigh()) {
  step_count = 1;
  refresh_display = true;
  last_refresh = millis();
}

which as I understand it does the opposite to what is desired.

Write this there instead:

if (FastGPIO::Pin<RESTART_CLK_PIN>::isInputHigh()) {
// this space intentionally left codeless
}
else {
  step_count = 1;
  refresh_display = true;
  last_refresh = millis();
}

HTH

a7

1 Like

alto777

THANK YOU!!!!!!!

that did the trick. My NANO is working perfectly now.

Sorry I didn't post the code in its entirety.

I didn't think that was OK, since I didn't write the original code.
It's my first time on the forum and this is Hagiwo's code for a 6 channel sequencer on a Nano.

I have made some other changes to my version so I could use a SH110x OLED ( the SSD1306 in Hagiwos version is too small.) I also added some switch debouncing for the encoder.
those worked no problems.
AND
The changes I posted were what I added so there would be a reset button.

In a musical context, with other instruments or sequences playing - A sequencer that just rolls along is not nearly as useful as one that you can start on the downbeat.

Again, THANKS a million.

Now I can go to the beach free of worry. :expressionless:

But srsly, I don't think I ever written a program, or even a sketch, where at some point something wasn't doing exactly the opposite to what I meant. Or thought.

LEDs can illuminate with HIGH or LOW depends on the circuit.

Switches can report HIGH or LOW when digitalRead() is called.

So you have to rock and roll with it. Usually it is as simple as changing LOW to HIGH or similar. It's code, use it like the hammer it can be.

Ppl will help themselves sometimes, viz:

# define PRESST LOW    // buttons pulled up HIGH normally

// then later

  bool alarmRequest = digitalRead(alarmButton) == PRESST;

// and use alarmRequest everywhere, don't read the button until next loop

  if (alarmRequest) makeSomeNoise();

Then if someone changes the way the switch is wired, you have one line of code that takes care of it everywhere

# define PRESST HIGH    // pulled down button (who does that? ;-)

HTH

a7

Aha,
I was looking through ARYTHMATIKs take on Hagiwos code and he has the digitalRead(xxx) implemented throughout.

I didn't quite understand how that was working + I'd done enough to change that OLED driver that I didn't want to drive the whole thing off a cliff. Learning.

I picked a different hammer and you - Alto - nailed it.
Enjoy the beach.

I took a quick look at the GitHub link and saw Euclid pop his head up.

Enjoy this

Online Euclidean Rhythms Demo

If you want to geek out on the maths, google and poke around

Godfried Toussaint Euclidean

like

wikipedia

He's written some papers and stuff. Beach reading…

a7

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.