Extend arduino shield button example with more buttons

I want to use more then one button on my arduino shield. Has anyone made or adjusted the button code example for this? My arduino skills are really not sufficient to get it working.
Would be awesome to get some help with this.

I’m in the middle of building an arduino CC device, and you’re welcome to see my code here: https://github.com/Chris-Nicholls/firehawk-chip-controller/blob/master/arduino/firehawk/firehawk.ino

I’m not sure it will be much use; I’m using an old pcb from a broken line 6 firehawk, so most of the code is dealing with that, but it does at least have multiple actuators.

The most relevant code is this though:

cc_actuator_t *getActuatorConfig(char* name, float* value){

    cc_actuator_config_t actuator_config;
    actuator_config.type = CC_ACTUATOR_MOMENTARY;
    actuator_config.name = name;

    actuator_config.min = 0.0;
    actuator_config.max = 1.0;
    actuator_config.value = value;
    actuator_config.supported_modes = CC_MODE_TOGGLE | CC_MODE_TRIGGER;
    actuator_config.max_assignments = 1;

    cc_actuator_t *actuator;
    actuator = cc.newActuator(&actuator_config);
    return actuator;
}

float switchState[] = {0,0,0,0,0,0};

void setup() {
    ...
    ...

    cc_device_t *device = cc.newDevice("DeviceName", uri);

    cc.addActuator(device, getActuatorConfig("Button-0", &switchState[0])); 
    cc.addActuator(device, getActuatorConfig("Button-1", &switchState[1])); 
    cc.addActuator(device, getActuatorConfig("Button-2", &switchState[2])); 
    cc.addActuator(device, getActuatorConfig("Button-3", &switchState[3])); 
    cc.addActuator(device, getActuatorConfig("Button-4", &switchState[4])); 
    cc.addActuator(device, getActuatorConfig("Button-5", &switchState[5])); 
 }

This will set up six toggle actuators, who’s values are read from an array of length six. To set a switch’s state, simply write the value into the switchState array and call cc.run()

(This is also my first time using an arduino, or writing C, so this might be terrible style, but it works for me.)
Hope that helps!

1 Like

Thx Chris,
I will give it a try as soon as I find some time. It seems like a very nice frist try I would say. I’m really comfortable in Max(/MSP) btw but in C it feels like I’m holiday in the south of France ;-). Good luck with your line 6 hacking project!

Dredging this up a bit. Two questions:

  • Are the buttons you’re using SPST switches?
  • Which pins are you connecting to on the Shield?

By looking at this part of the code:

void readSwitchState(float newState, float* currentState, char* debounceTime){
if (newState != *currentState){
(*debounceTime)++;
}else{
*debounceTime = 0;
}
if (*debounceTime >= DEBOUNCE_REPEATS){
*currentState = newState;
}
}

I would say that yes, it’s SPST switches, but I’m not super sure…just checking the code.

If I’m not seeing wrong it’s in the code:

unsigned char s0 = 11, s1 = 12, s2 = 13;

Understood, @jon. I’m pretty far out of my depth with Arduino at the moment, so I’m trying to figure things out to get to the level I want. From what I’ve read, buttons and the like go to D0-D13 pins, and pots/TRS go to the A0-A5 pins.

I’m working on a small pedal with a button and two TRS inputs, and once I’ve got that figured out, I’ll start working on a large one with a display, a button, and two rotary encoders. Biggest thing I’m working on is figuring out how to merge codes from multiple examples.

1 Like

No worries :slight_smile:
Actually I’m curious to check the result of those projects. Please share it with us.

Little tip: digital inputs can use only the number (and that’s why he has s0 = 11, the switch is connected to pin 11). The analogs require the “A” before.

2 Likes