6 way push button switch?

I’m trying to make the “Big button” sequencer by lookmumnocomputer, and don’t have a six-way rotary switch, and they’re kinda pricey. Is there some way I can achieve this with a simple push button and some code? I need it to be so I can Turn on the Arduino the first LED lights up then You push the button and the second LED lights up and changes channels and so forth

Any way I could do this? Plz help thanks!

Using one button.... Let the Arduino start at LED 1. Every time You press the button the next LED is turned on. When having the last LED lit next button press goes to LED 1.

To realize what Railroader suggested look at the state change detection tutorial. Choose the LED to light using the value of the buttonPushCounter.

Here is an adaptation of the state change detection example to illustrate the above. Note that the push button switch is wired to ground with the input set to INPUT_PULLUP so the switch input is active LOW instead of active HIGH like the unmodified example. The LED pins are in an array to make programming easier.

// by C Goulding aka groundFungus


const byte  buttonPin = 2;    // the pin that the pushbutton is attached to
const byte NUMLED = 6;
const byte ledPins[NUMLED] = {3, 4, 5, 6, 7, 8};;  // the pins to which the LEDs are attached

boolean buttonState = 0;         // current state of the button
boolean lastButtonState = 0;     // previous state of the button
byte buttonPushCounter = 0;
void setup()
{
   // initialize the button pin as a input with internal pullup enabled
   pinMode(buttonPin, INPUT_PULLUP);
   // initialize the LEDs as an outputs:
   for (int n = 0; n < NUMLED; n++)
   {
      pinMode(ledPins[n], OUTPUT);
   }
   // initialize serial communication:
   Serial.begin(9600);
}

void loop()
{
   static unsigned long timer = 0;
   unsigned long interval = 50;  // check switch 20 times per second
   if (millis() - timer >= interval)
   {
      timer = millis();
      // read the pushbutton input pin:
      buttonState = digitalRead(buttonPin);
      // compare the new buttonState to its previous state
      if (buttonState != lastButtonState)
      {
         if (buttonState == LOW)
         {
            // if the current state is LOW then the button
            // went from off to on:
            for (int n = 0; n < NUMLED; n ++) // turn all LEDs off
            {
               digitalWrite(ledPins[n], LOW);
            }
            digitalWrite(ledPins[buttonPushCounter], HIGH); // turn on one LED
            buttonPushCounter++;
            if(buttonPushCounter > NUMLED)
            {
               buttonPushCounter = 0;
            }
         }
      }
      // save the current state as the last state,
      //for next time through the loop
      lastButtonState = buttonState;
   }
}

If you've got a pot lying around you could run that into an analog input and thence through the map() function to get your six positions. It won't do 360° tho'.

Peter_Dodge:
I’m trying to make the “Big button” sequencer by lookmumnocomputer, and don’t have a six-way rotary switch, and they’re kinda pricey.

Kinda pricey?

On the site https://www.lookmumnocomputer.com/big-button ,he gives a link to one for £1.28.
I don't call that expensive.

Rotary switch - £1.28

Here's an old 1 button selector I wrote years ago, might give you some ideas. Connect button from pin 4 to GND.

uint32_t tStart, timeStart, tEnd;// = 2000UL;
int speeds [] = {1, 2, 3, 4, 5, 6};
int speed;
const byte dbTime = 30, btn = 4, ledPin = 13;
bool btnState = false, bState = true, oldBstate = true,
     timing = false, speedSet = false;
byte cntr;

void setup()
{
  Serial.begin(115200); // set serial monitor baud rate to match
  pinMode(btn, INPUT_PULLUP);
  pinMode(ledPin, OUTPUT);
}

void loop()
{
// debounce-----------------------------
  if (digitalRead(btn) != btnState) // they are different!
  {
    btnState ^= 1;                  // make them equal
    timeStart = millis();           // restart timer
  }
  if (millis() - timeStart > dbTime)  // if not changed for dbTime,
     bState = btnState; // btnState is valid, use it
// end debounce-------------------------
  
  if(!timing && !bState && oldBstate)
  {
    tStart = millis();
    tEnd = 1500UL;
    cntr = 0;
    timing = true;
    speedSet = true;
    
  }

  
  if(timing && !bState && oldBstate)
  {
    if(++cntr > 6)
      cntr = 1;
    tStart = millis();
    Serial.println(speeds[cntr - 1]);
    oldBstate = bState;
  }

  if(millis() - tStart > tEnd)
  {
    timing = false;    
    if(speedSet)
    {
      speed = speeds[cntr - 1];
      if(!bState)
        speed = 0;
      Serial.print("Speed set to ");
      Serial.println(speed);
      Serial.println("Press button to change");
      speedSet = false;
    }
  }
  digitalWrite(ledPin,timing);
  oldBstate = bState;
}

Peter_Dodge:
I’m trying to make the “Big button” sequencer by lookmumnocomputer, and don’t have a six-way rotary switch, and they’re kinda pricey.

Pricy..??...you have to be kidding.

Also , link says it's a 12way 1 pole.

I don't think a push button is a suitable substitute for a rotary switch because the position of the rotary switch provides feedback to the user. Also a user can reverse a rotary switch by one position if he accidentally moves it a step too far. Reversing direction is just not possible with a single push button.

Creating a push-button system with suitable user feedback feedback would be a lot of work - and the user would have to cycle through all the options to get from position 3 to position 2

...R

(deleted)

You can reverse a single button setup with a long press

Peter_Dodge:
I’m trying to make the “Big button” sequencer by lookmumnocomputer, and don’t have a six-way rotary switch, and they’re kinda pricey. Is there some way I can achieve this with a simple push button and some code? I need it to be so I can Turn on the Arduino the first LED lights up then You push the button and the second LED lights up and changes channels and so forth

Any way I could do this? Plz help thanks!

I’m surprised in keeping with the “lookmumnocomputer” you didn’t use a CD4017 decade IC and sequence its outputs.
Like this.


From here;

Tom… :slight_smile:

gogreenpower2:
You can reverse a single button setup with a long press

You can in theory, but I would expect that the whole thing just makes for a very frustrating user experience - how does the user know whether the change to reverse has actually taken place, for example. Or what about the situation where he makes a long press by accident.

...R

Oh dear! Where do we start?

Well, the diagram shows the LED corresponding to the "big button" connected to analog pin 6 which is input only, but the text corrects it to A3. They had to realise that blunder.

The 78L05 is missing its input and output capacitors.

Those clear errors noted, the 6 way selector switch is actually used by coding a resistor ladder to an analog input using one pin only. So it could (if it in fact was expensive) be substituted with a 10k potentiometer. Of course, a 12 way switch would work just as well as the six way, you could use a symmetrical "diamond-shaped" knob. :grinning:

So if you replaced it with something other than the resistor bank, you have only one I/O port to use. The problem with a button - or even two buttons for "up" and "down" is knowing the current position because here you only have the 6 LEDs that when activated, actuate a drum. So this would be rather "immersive" feedback.