Commit 2a4907cc authored by Jacob Vosmaer's avatar Jacob Vosmaer

Respond to MIDI note on pitch

parent f7a78c3a
......@@ -5,28 +5,40 @@
#include "voices.h"
#include "dac.h"
void
io_init(void)
{
// More outputs to save power; PORTB6/7 is XTAL
DDRB = _BV(PORTB0) | _BV(PORTB1) | _BV(PORTB2) | _BV(PORTB3) | _BV(PORTB4) | _BV(PORTB5);
// More outputs to save power; PORTC6 is reset, "PORTC7" does not exist (?)
DDRC = _BV(PORTC0) | _BV(PORTC1) | _BV(PORTC2) | _BV(PORTC3) | _BV(PORTC4) | _BV(PORTC5);
// PORTD0 is UART RX. Set all other PORTD pins output, to save power.
DDRD = _BV(PORTD1) | _BV(PORTD2) | _BV(PORTD3) | _BV(PORTD4) | _BV(PORTD5) | _BV(PORTD6) | _BV(PORTD7);
}
int
main(void)
{
DDRB = _BV(PORTB0) | _BV(PORTB1) | _BV(PORTB2) | _BV(PORTB3) | _BV(PORTB4) | _BV(PORTB5); // More outputs to save power; PORTB6/7 is XTAL
DDRC = _BV(PORTC0) | _BV(PORTC1) | _BV(PORTC2) | _BV(PORTC3) | _BV(PORTC4) | _BV(PORTC5); // More outputs to save power; PORTC6 is reset, "PORTC7" does not exist (?)
DDRD = _BV(PORTD1) | _BV(PORTD2) | _BV(PORTD3) | _BV(PORTD4) | _BV(PORTD5) | _BV(PORTD6) | _BV(PORTD7); // PORTD0 is UART RX. Set all other PORTD pins output, to save power.
io_init();
dac_init();
midi_init();
DDRB |= _BV(PORTB0); // debug led
for (uint8_t i = 0 ;; i = (i + 12) % 128) {
for (uint8_t j = 0; j < NUM_VOICES; j++) {
dac_set_note(j, i);
for (;;) {
if (!midi_read()) {
continue;
}
// debug blink
PORTB |= _BV(PORTB0);
_delay_ms(100);
PORTB &= ~_BV(PORTB0);
if (midi_status() == MIDI_NOTE_ON) {
uint8_t key = midi_data() >> 8;
uint8_t velocity = midi_data() & 0xff;
_delay_ms(5000);
if (velocity) {
for (uint8_t i = 0; i < NUM_VOICES; i++) {
dac_set_note(i, key);
}
}
}
}
return 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment