ECE 4760 Final Project
 All Files Functions Variables Enumerations Enumerator Macros
Macros | Functions | Variables
project.c File Reference
#include <inttypes.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdio.h>
#include <math.h>
#include "imu.h"
#include <util/delay.h>
#include "midi.h"
#include "uart.h"

Go to the source code of this file.

Macros

#define t1   25
 
#define WAIT_VALUE   (300 / t1)
 
#define RATE_THRES   (240)
 

Functions

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. More...
 
void initialize (void)
 
void get_pitch_roll (float *pitch, float *roll)
 This function reads the accelerometer and calculates the pitch and roll of the device. More...
 
void play_note_off (void)
 Turns the note we had stored in the note global varible off. More...
 
void play_note_on (uint8_t n)
 Sends the MIDI note on signal on the serial line with the note specified in the parameter at velocity 100. stores the note in a global variable so we can turn it off at a later time. More...
 
 ISR (TIMER0_COMPA_vect)
 This ISR keeps a millisecond timer for timing the main task. More...
 
int main (void)
 
 ISR (ADC_vect)
 Rather than waiting in while loop for the ADC readings, we use the ADC interupt that sets the values asynchronously. This function checks to see if the values of the flex resistors have indicted whether a finger has been bent or not. If the value of Chanel 0 of the ADC is greater than 250 we set a flag to play a note, if it is less than 245, we set a flag to end the note. The other flex resitor, on the middle finger has a larger range so determining whether it is on or off is easier, we merely check to see if it is greater than 240, and set the appropiate flag. More...
 
char handle_notes (float roll)
 Takes the current roll and determines if a note needs to be played or turned off. It calculates the note from the roll. We are playing notes only on a major scale. It can be transposed up or down. More...
 

Variables

FILE uart_str = FDEV_SETUP_STREAM(uart_putchar, uart_getchar, _FDEV_SETUP_RW)
 
char play_on = 0
 if 1 a note is played More...
 
char play_off = 0
 if 0 a note is turned off More...
 
volatile char chan1
 
volatile char adc_chan1_on
 whether or not the middle note is held down. More...
 
volatile unsigned int time1
 task1 counter More...
 
char channel = 0
 
uint8_t instrument = 0
 counter to keep track of what instrument is on the MIDI channel More...
 
uint8_t note = 60
 Current note being played. More...
 
uint8_t base_note = 0
 base_note for transposing the C-major scale More...
 
uint16_t time = 0
 
uint16_t wait = WAIT_VALUE
 
float old_roll
 used to keep track of the roll so we can bend the pitch relative to the note it was played at. More...
 
char cmajor [15] = {48, 50, 52, 53, 55, 57, 59, 60, 62, 64, 65, 67, 69, 71, 72}
 C-major scale in MIDI notes can add or subtract a value to transpose to different keys. More...
 

Macro Definition Documentation

#define RATE_THRES   (240)

Definition at line 145 of file project.c.

#define t1   25

Definition at line 18 of file project.c.

#define WAIT_VALUE   (300 / t1)

Definition at line 144 of file project.c.

Function Documentation

void get_pitch_roll ( float *  pitch,
float *  roll 
)

This function reads the accelerometer and calculates the pitch and roll of the device.

Parameters
pitchpointer to a float that will contain the current pitch measured by the accelerometer.
rollpointer to a float that will contain the current roll measured by the accelerometer.

Definition at line 120 of file project.c.

char handle_notes ( float  roll)

Takes the current roll and determines if a note needs to be played or turned off. It calculates the note from the roll. We are playing notes only on a major scale. It can be transposed up or down.

Parameters
roll- roll of the glove
Returns
1 if a new note was played, 0 otherwise

Definition at line 211 of file project.c.

void initialize ( void  )

Definition at line 261 of file project.c.

ISR ( TIMER0_COMPA_vect  )

This ISR keeps a millisecond timer for timing the main task.

Definition at line 50 of file project.c.

ISR ( ADC_vect  )

Rather than waiting in while loop for the ADC readings, we use the ADC interupt that sets the values asynchronously. This function checks to see if the values of the flex resistors have indicted whether a finger has been bent or not. If the value of Chanel 0 of the ADC is greater than 250 we set a flag to play a note, if it is less than 245, we set a flag to end the note. The other flex resitor, on the middle finger has a larger range so determining whether it is on or off is easier, we merely check to see if it is greater than 240, and set the appropiate flag.

Definition at line 81 of file project.c.

int main ( void  )

Entry point and task scheduler loop

Definition at line 62 of file project.c.

void play_note_off ( void  )

Turns the note we had stored in the note global varible off.

Definition at line 253 of file project.c.

void play_note_on ( uint8_t  n)

Sends the MIDI note on signal on the serial line with the note specified in the parameter at velocity 100. stores the note in a global variable so we can turn it off at a later time.

Parameters
n- note to play.

Definition at line 243 of file project.c.

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.

Definition at line 159 of file project.c.

Variable Documentation

volatile char adc_chan1_on

whether or not the middle note is held down.

Definition at line 38 of file project.c.

uint8_t base_note = 0

base_note for transposing the C-major scale

Definition at line 142 of file project.c.

volatile char chan1

Definition at line 34 of file project.c.

char channel = 0

Definition at line 71 of file project.c.

char cmajor[15] = {48, 50, 52, 53, 55, 57, 59, 60, 62, 64, 65, 67, 69, 71, 72}

C-major scale in MIDI notes can add or subtract a value to transpose to different keys.

Definition at line 203 of file project.c.

uint8_t instrument = 0

counter to keep track of what instrument is on the MIDI channel

Definition at line 134 of file project.c.

uint8_t note = 60

Current note being played.

Definition at line 138 of file project.c.

float old_roll

used to keep track of the roll so we can bend the pitch relative to the note it was played at.

Definition at line 153 of file project.c.

char play_off = 0

if 0 a note is turned off

Definition at line 28 of file project.c.

char play_on = 0

if 1 a note is played

Definition at line 24 of file project.c.

uint16_t time = 0

Definition at line 143 of file project.c.

volatile unsigned int time1

task1 counter

Definition at line 42 of file project.c.

FILE uart_str = FDEV_SETUP_STREAM(uart_putchar, uart_getchar, _FDEV_SETUP_RW)

Definition at line 14 of file project.c.

uint16_t wait = WAIT_VALUE

Definition at line 147 of file project.c.