Hello fellow Electro-Techs, thank you for your time!! I am currently in the process of combining my love for music with my fascination with ucontrollers and am trying to design a midi to cv converter by myself. I am analysing a code and am currently stuck with the following. It is for a ATtiny2313, the idea is that incoming MIDI data in converted via the Tiny, and then sent to a DAC. BITS 5,6, and 7 of PORT B are the outputs to the DAC. BIT 0 of PORT D is the MIDI input. the rest of PORT D is unused (no idea why they are high).
void make_cv() {
static uint8_t dac_value = 0;
dac_value = (last_active_key()-36)<<1;
PORTD &= ~(0b00111100); // Put Port D bit 2,3,4,5 LOW
PORTD |= (dac_value & 0x0F)<<2;
PORTB &= ~(0b11100000); // Put Port B bit 5,6,7 LOW
PORTB |= (dac_value & 0xF0)<<1;
So last_active_key is a function that returns (as expected) the last key played on a monosynth. Why is it subtracted from 36? what is happening there?
and what does << do?
I have attached a Schematic if it helps!
void make_cv() {
static uint8_t dac_value = 0;
dac_value = (last_active_key()-36)<<1;
PORTD &= ~(0b00111100); // Put Port D bit 2,3,4,5 LOW
PORTD |= (dac_value & 0x0F)<<2;
PORTB &= ~(0b11100000); // Put Port B bit 5,6,7 LOW
PORTB |= (dac_value & 0xF0)<<1;
So last_active_key is a function that returns (as expected) the last key played on a monosynth. Why is it subtracted from 36? what is happening there?
and what does << do?
I have attached a Schematic if it helps!
Attachments
Last edited: