Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SendOnlySoftwareSerial.h.h>
- #define MIDICHAN 15 // RK008 midi channel needs to be set to ch 16
- // code from http://www.eddevane.com/blog/simple-midi-controller-with-attiny85
- // adapted serial TX only lib to free up easy pin for midi current:
- // https://github.com/nickgammon/SendOnlySoftwareSerial
- // pinout
- /*
- --U--
- PB5 RST ---1-| |-8---VCC (RK008 SYNC TIP)
- PB3 IN2 ---2-| |-7 PB2 ---IN0
- PB4 IN1 ---3-| |-6 PB1 ---TX --> 220ohm MIDI CURRENT
- (RK008 SYNC GND) GND ---4-| |-5 PB0 ---5v --> 220ohm MIDI SOURCE
- ------
- */
- // Variables:
- byte cc = 0;
- byte AnalogValue = 0; // define variables for the controller data
- byte lastAnalogValue[3]; // define the "lastValue" variables
- byte thresh = 8;// bigger value for switches instead of pots
- byte ports[]={1,2,3}; // GPIO input ports
- byte ccnumber[3] = {105,115,117}; // RK008 number for stop/play/rec CC
- //software serial, pin RX(0) not used, we use hardware input
- SendOnlySoftwareSerial midiSerial(1); // digital pins that we'll use for soft serial RX & TX
- // Continuous Controller Function
- void controlChange(byte ChannelByte,byte ControlNumber,byte ControlValue){
- midiSerial.write(ChannelByte + 0xb0);
- midiSerial.write(ControlNumber);
- midiSerial.write(ControlValue);
- }
- void setup() {
- // launch MIDI serial port
- midiSerial.begin(31250);
- pinmode(0,OUTPUT);
- DDRB &= ~(1 << PB2); // Set the pin PB2 as input
- PORTB |= (1 << PB2); //activate pull-up resistor for PB2
- DDRB &= ~(1 << PB3); // Set the pin PB3 as input
- PORTB |= (1 << PB3); //activate pull-up resistor for PB3
- DDRB &= ~(1 << PB4); // Set the pin PB3 as input
- PORTB |= (1 << PB4); //activate pull-up resistor for PB4
- DDRB |= (1 << PB0); // Set the pin PB0 as output
- PORTB |= (1 << PB0); //set PB0 to HIGH
- }
- void loop() {
- // read the 3 inputs
- for(int i = 0; i < 3; i++){
- cc = analogRead(ports[i])/8;
- if(abs(cc - lastAnalogValue[i]) > (thresh)) { // is there a difference beyond threshold?
- controlChange(MIDICHAN, ccnumber[i], cc); // send the CCs for stop/play/rec on midi channl #MIDICHAN
- lastAnalogValue[i] = cc;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement