Extend arduino shield button example with more buttons


#1

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.


#2

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!


#3

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!