Advertisement
Midge

Control Line 6 POD2 With MIDI using an ATTiny85

Mar 22nd, 2017
514
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. //Arduino IDE Code for sending up/down MIDI signals to a Line 6 POD 2.0 with an ATTiny85
  2. //tested but offered 'as is' without support
  3.  
  4. #include <SoftwareSerial.h> //Microcontroller is an ATiny85 so using the SoftwareSerial library
  5.  
  6. SoftwareSerial mySerial(2,3); //RX =2, TX = ATTiny85 pin 2, PB3; MIDI transmit pin
  7. byte status_byte = B11000000; //Status number 192 for program\bank change, hex = C0
  8. byte count_val = 38; // Set a start variable at 38 to avoid 'rollover' error when moving down\up patches
  9.  
  10. // MIDI send function
  11. void send_byte(byte value) {
  12. byte patch_value = value % 37; // Set patch_value= 0 to 36 (0 is manual)
  13. // Re: Rollover, Byte type is unsigned, Binary 0 minus 1 is B11111111(255), and 255 mod 37 is 33. Hence the following count value reset
  14. if(patch_value == 1) count_val = 38; //reset count_val to avoid rollover error
  15. mySerial.write(status_byte); //send status byte
  16. mySerial.write(patch_value); //send patch value byte
  17. delay(500); //wait (simple debounce and pause)
  18. }
  19.  
  20. void setup() {
  21. DDRB = B00001000; //Set PortB direction, in on PB0 and PB1 out on PB3
  22. PORTB = B00000011; //Switch on internal pull up resistors
  23. mySerial.begin(31250); //set MIDI baud rate (NB: Microcontroller fuses set to 8Mhz internal clock)
  24. send_byte(count_val); //Send an initial start value, = Patch A1
  25. }
  26.  
  27. void loop() {
  28. byte readpins = PINB | B11111100; //read pins once per loop, unpressed switch with pullups = 1 so bitmask applied to unused bits will always TRUE
  29. if (~readpins){ //Switches have pull-ups, ~readpins will return TRUE when one is pushed
  30. byte switch_val=~readpins; //inverse of inputs
  31.  
  32. switch (switch_val) {
  33. case B01: //Switch PB0 on
  34. {count_val-- ;
  35. send_byte(count_val);}
  36. break;
  37. case B10: //Switch PB1 on
  38. {count_val++ ;
  39. send_byte(count_val);}
  40. break;
  41. }}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement