Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Arduino IDE Code for sending up/down MIDI signals to a Line 6 POD 2.0 with an ATTiny85
- //tested but offered 'as is' without support
- #include <SoftwareSerial.h> //Microcontroller is an ATiny85 so using the SoftwareSerial library
- SoftwareSerial mySerial(2,3); //RX =2, TX = ATTiny85 pin 2, PB3; MIDI transmit pin
- byte status_byte = B11000000; //Status number 192 for program\bank change, hex = C0
- byte count_val = 38; // Set a start variable at 38 to avoid 'rollover' error when moving down\up patches
- // MIDI send function
- void send_byte(byte value) {
- byte patch_value = value % 37; // Set patch_value= 0 to 36 (0 is manual)
- // 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
- if(patch_value == 1) count_val = 38; //reset count_val to avoid rollover error
- mySerial.write(status_byte); //send status byte
- mySerial.write(patch_value); //send patch value byte
- delay(500); //wait (simple debounce and pause)
- }
- void setup() {
- DDRB = B00001000; //Set PortB direction, in on PB0 and PB1 out on PB3
- PORTB = B00000011; //Switch on internal pull up resistors
- mySerial.begin(31250); //set MIDI baud rate (NB: Microcontroller fuses set to 8Mhz internal clock)
- send_byte(count_val); //Send an initial start value, = Patch A1
- }
- void loop() {
- byte readpins = PINB | B11111100; //read pins once per loop, unpressed switch with pullups = 1 so bitmask applied to unused bits will always TRUE
- if (~readpins){ //Switches have pull-ups, ~readpins will return TRUE when one is pushed
- byte switch_val=~readpins; //inverse of inputs
- switch (switch_val) {
- case B01: //Switch PB0 on
- {count_val-- ;
- send_byte(count_val);}
- break;
- case B10: //Switch PB1 on
- {count_val++ ;
- send_byte(count_val);}
- break;
- }}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement