4 #include <avr/interrupt.h>
8 #include <util/delay.h>
50 ISR (TIMER0_COMPA_vect)
83 uint8_t analog = ADCH;
87 if (analog > 250 && !
chan1) {
92 if (analog < 245 &&
chan1) {
124 *pitch = atan2(x, sqrt((y * y) + (z * z)));
125 *roll = atan2(y, sqrt((x * x) + (z * z)));
126 *pitch *= 180.0 / M_PI;
127 *roll *= 180.0 / M_PI;
144 #define WAIT_VALUE (300 / t1)
145 #define RATE_THRES (240)
203 char cmajor[15] = {48, 50, 52, 53, 55, 57, 59, 60, 62, 64, 65, 67, 69, 71, 72};
221 int8_t iroll = (int8_t)froll;
281 stdout = stdin = stderr = &
uart_str;
282 ADMUX = (1<<ADLAR) | (1<<REFS0);
283 ADCSRA = (1<<ADEN) | (1<<ADIF) | (1<<ADIE) + 7;
uint8_t instrument
counter to keep track of what instrument is on the MIDI channel
volatile unsigned int time1
task1 counter
void get_pitch_roll(float *pitch, float *roll)
This function reads the accelerometer and calculates the pitch and roll of the device.
char play_off
if 0 a note is turned off
char handle_notes(float)
Takes the current roll and determines if a note needs to be played or turned off. It calculates the n...
void pitch_bend(uint8_t channel, int16_t value)
int uart_putchar(char c, FILE *stream)
float old_roll
used to keep track of the roll so we can bend the pitch relative to the note it was played at...
void play_note_off(void)
Turns the note we had stored in the note global varible off.
void play_note_on(uint8_t y)
Sends the MIDI note on signal on the serial line with the note specified in the parameter at velocity...
uint8_t note
Current note being played.
int uart_getchar(FILE *stream)
char play_on
if 1 a note is played
ISR(TIMER0_COMPA_vect)
This ISR keeps a millisecond timer for timing the main task.
uint16_t init_imu(enum gyro_scale gScl, enum accel_scale aScl, enum mag_scale mScl, enum gyro_odr gODR, enum accel_odr aODR, enum mag_odr mODR)
Initilizes the IMU and enables all 9 axes and set the respective scales and data rates.
void read_gyro(float *x, float *y, float *z)
Reads the gyroscope and calculates the real value from the raw reading.
void change_instrument(uint8_t channel, uint8_t instrument)
void task1(void)
This function is the function that gets called every 25ms that handles the main logic, it reads the sensor values, checks flags set by the ADC interrupt vector, and sends the according MIDI signals.
void send_note(uint8_t channel, uint8_t vel, uint8_t pitch)
volatile char adc_chan1_on
whether or not the middle note is held down.
void read_accel(float *x, float *y, float *z)
Reads the accelometer and calculates the real value from the raw reading.
char cmajor[15]
C-major scale in MIDI notes can add or subtract a value to transpose to different keys...
uint8_t base_note
base_note for transposing the C-major scale
void send_note_off(uint8_t channel, uint8_t vel, uint8_t pitch)