Advertisement
retrokits

RK008 button input

Jun 23rd, 2023 (edited)
951
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 2.22 KB | Music | 0 0
  1. #include <SendOnlySoftwareSerial.h.h>
  2. #define MIDICHAN 15 // RK008 midi channel needs to be set to ch 16
  3.  
  4. // code from http://www.eddevane.com/blog/simple-midi-controller-with-attiny85
  5. // adapted serial TX only lib to free up easy pin for midi current:
  6. // https://github.com/nickgammon/SendOnlySoftwareSerial
  7.  
  8. // pinout
  9. /*
  10.                            --U--
  11.              PB5 RST ---1-|     |-8---VCC (RK008 SYNC TIP)
  12.              PB3 IN2 ---2-|     |-7 PB2 ---IN0
  13.              PB4 IN1 ---3-|     |-6 PB1 ---TX --> 220ohm MIDI CURRENT
  14. (RK008 SYNC GND) GND ---4-|     |-5 PB0 ---5v --> 220ohm MIDI SOURCE
  15.                           ------
  16.  
  17. */
  18.  
  19. // Variables:
  20. byte cc = 0;
  21. byte AnalogValue = 0; // define variables for the controller data
  22. byte lastAnalogValue[3]; // define the "lastValue" variables
  23. byte thresh = 8;// bigger value for switches instead of pots
  24. byte ports[]={1,2,3}; // GPIO input ports
  25. byte ccnumber[3] = {105,115,117}; // RK008 number for stop/play/rec CC
  26. //software serial, pin RX(0) not used, we use hardware input
  27. SendOnlySoftwareSerial midiSerial(1); // digital pins that we'll use for soft serial RX & TX
  28.  
  29. // Continuous Controller Function
  30. void controlChange(byte ChannelByte,byte ControlNumber,byte ControlValue){
  31.   midiSerial.write(ChannelByte + 0xb0);
  32.   midiSerial.write(ControlNumber);
  33.   midiSerial.write(ControlValue);
  34. }
  35.  
  36. void setup() {
  37.   //  launch MIDI serial port
  38.  
  39.   midiSerial.begin(31250);
  40.   pinmode(0,OUTPUT);
  41.   DDRB &= ~(1 << PB2); // Set the pin PB2 as input
  42.   PORTB |= (1 << PB2);  //activate pull-up resistor for PB2
  43.   DDRB &= ~(1 << PB3); // Set the pin PB3 as input
  44.   PORTB |= (1 << PB3);  //activate pull-up resistor for PB3
  45.   DDRB &= ~(1 << PB4); // Set the pin PB3 as input
  46.   PORTB |= (1 << PB4);  //activate pull-up resistor for PB4
  47.  
  48.   DDRB |= (1 << PB0); // Set the pin PB0 as output
  49.   PORTB |= (1 << PB0); //set PB0 to HIGH
  50.  
  51. }
  52.  
  53. void loop() {
  54.   // read the 3 inputs
  55.   for(int i = 0; i < 3; i++){
  56.     cc = analogRead(ports[i])/8;
  57.     if(abs(cc - lastAnalogValue[i]) > (thresh)) { // is there a difference beyond threshold?
  58.       controlChange(MIDICHAN, ccnumber[i], cc); // send the CCs for stop/play/rec on midi channl #MIDICHAN
  59.       lastAnalogValue[i] = cc;
  60.     }
  61.   }
  62. }
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement