Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Button input test on the RK002
- * You can use the outer pins of the orange RK002 DIN5 for output or input, in this example we scan for a button press on one of the pins and insert a sequencer start/stop command into the midi stream
- *
- * It is an illustration of what is possible. We have an RK-202 adapter to add buttons to the RK002 DIN5 plug which exposes it for button connections.
- *
- * This simple example uses it to insert sequencer start stop commands
- * ...but you could also add patch changes + / - or e.g. even initiate sysex dumps on a single button press.
- *
- *
- * This example in action with the RK-202 buttonboard: https://www.instagram.com/p/CeEXg5cNAHt/
- *
- * button1 (black): tempo start / stop
- * button2 (red) : tap tempo (for internal tempo generator only)
- *
- */
- // ******************************************
- // NOTE: Activate GPIO functions on hardware layout
- // ******************************************
- #define BUTTON1 13
- #define BUTTON2 6
- // WAITTIME is xx times 10mS so 16 = 160mS debounce time, if too short/long, you can change it here
- #define WAITTIME 16
- // heartbeattmr holds a counter for waittime
- byte heartbeattmr = 0;
- bool buttons[2] = {false,false} ; // state variables for button lock during debouncing
- bool clock_run=false;
- void onButton1(){
- if(buttons[0]==false){
- if(clock_run){ // is running so stop
- clock_run=false;
- RK002_sendStop();
- }else{
- RK002_sendStart();
- clock_run=true;
- }
- buttons[0]=true;
- heartbeattmr=WAITTIME;
- }
- }
- void onButton2(){
- if(buttons[1]==false){
- RK002_clockTap(); // tap tempo
- buttons[1]=true;
- heartbeattmr=WAITTIME;
- }
- }
- bool RK002_onClock(){
- return true;
- }
- bool RK002_onStart(){
- clock_run=true;
- return true;
- }
- bool RK002_onStop(){
- clock_run=false;
- return true;
- }
- bool RK002_onContinue(){
- clock_run=!clock_run;
- return true;
- }
- void setup()
- {
- /* 0 GPIO 6 (run)
- * 0 5V
- * 0 GND [= orange connector, pin side view
- * 0 DATA
- * 0 GPIO 13 (clk)
- */
- pinMode(BUTTON1,INPUT_PULLUP); // button 1 input
- attachInterrupt(digitalPinToInterrupt(BUTTON1),onButton1,FALLING);
- pinMode(BUTTON2,INPUT_PULLUP); // button 2 input
- attachInterrupt(digitalPinToInterrupt(BUTTON2),onButton2,FALLING);
- RK002_clockSetTempo(1280); // no external tempo? set to 128BPM
- RK002_clockSetMode(0); // use external clock if available
- }
- void RK002_onHeartBeat() // we use heartbeat for button debouncing
- {
- // is timer running (button scanned) ?
- if (heartbeattmr > 0)
- {
- heartbeattmr--;
- if (heartbeattmr == 0)
- {
- //Timeout occured, enable reading of buttons again (WAITTIME x 10mS)
- if(buttons[0]==true) buttons[0]=false;
- if(buttons[1]==true) buttons[1]=false;
- }
- }
- }
- void loop()
- {
- }
Add Comment
Please, Sign In to add comment