Auto Strumming Guitar Software

The full code for this project can be viewed on Github at the link: https://github.com/SheldonB/Automated-Guitar-Player 

The software side of the project was setup to be as modular as possible. Every piece of the software is in its own file. To structure musical ‘notes’, we created a struct that contains two members: An alias to a GPIO pin to toggle the solenoid for a particular string, and a delay in ms used to wait after the note is finished. We can then make an array of these structs to create a song. We programmed in 3 distinct songs: Stairway to Heaven, Miserlou, and a simple arpeggio. We use a play song function to iterate through the array of notes provided, and then we call another function called solenoid_high_low to toggle the solenoids. In this function, we toggle the pin associated with a particular solenoid, wait a certain amount of time (this varies depending on the delay between the notes), and then we toggle the pin again. More songs or rhythms could be added to the A3BU easily. An array of SongNote structs needs to be created that contains the string to be played and the time to wait till the next note.

The code snippet that plays the song is below:


#include <util/delay.h>

#include "jets_util.h"
#include "music.h"
#include "solenoid.h"

//Simple Arpegio
struct SongNote SAMPLE_SONG[] = {
 {STRING_SIX, 300},
 {STRING_FIVE, 300},
 {STRING_FOUR, 300},
 {STRING_THREE, 300},
 {STRING_TWO, 300},
 {STRING_ONE, 300}
};

//Stairway to Heaven
struct SongNote STAIRWAY[] = {
 {STRING_FOUR, 10},
 {STRING_ONE, 800},
 {STRING_TWO, 800},
 {STRING_THREE, 800},
 {STRING_FOUR, 10},
 {STRING_ONE, 800}
};

struct SongNote MISERLOU[] = {
 {STRING_ONE, 100}
};

unsigned int SAMPLE_SONG_LENGTH = 6;

/*
Loops through an array of song notes
and calls the play_note function on each of those notes
*/
void play_song(struct SongNote song[], unsigned int length)
{
 unsigned int i;
 for (i = 0; i < length; i++)
 {
 play_note(song[i]);
 } 
}

/*
Takes a SongNote Struct and then toggels that solenoid
and then delays a certain time. A SongNote struct has a port to 
toggle high then low, then a delay till the next not should be played
*/
void play_note(struct SongNote note)
{
 solenoid_high_low(note.port);
 jets_delay_ms(note.delay);
}

Auto Strumming Guitar: The Big Picture

Solenoid Placement on Guitar

The goal of this project was to program and utilize an A3BU Micro-controller to play a guitar. The micro-controller was programmed with 3 songs that users would have to do the fretting for, as well as the ability to use serial communication to play individual strings on the guitar. This project was a success, the solenoids pluck the strings, producing sounds with the intended speed, whether programmed or based on the serial communication.