Secured Music Box – Code Snippets

Snippet 1:

 

For our project, one of the aspects of our code which may set our group apart from the rest is that we decided make our buzzer play a song.  We accomplished this by changing the frequency of PWM signals which served as the input to the buzzer.  Because the pwm_init() function provided a method to set the frequency in Hz, we were able to look up the specific frequency of certain notes and, in turn, set that as the output to the buzzer.  In order to make distinct notes, we started an output to the buzzer input with a dutycycle of 50, set a delay for the length of the note, changed the dutycycle to 0 to stop the note, and set a shorter delay to make a note distinct.  Whenever the song (we used Jingle Bells) changed notes, we then would have to recall the pwm_init() function to change the frequency of the output, before repeating the steps above to play a distinct note.

 

Snippet 2:

In the above part of our project code, we used code modified from the ADC Internal Temperature Example code to read the input from the magnetic field sensor. This sensor returns either a high or low signal to one pin depending on the presence of a magnetic field close to the sensor.  Because the code from this example used the value result as a measure of Voltage in mV, we simply used an if statement which sets a variable equal to one or zero depending on whether or not the sensor returned a logic high or logic low.  Then depending on this variable we used gfx methods to print applicable strings to the LCD on the A3BU, and sets the applicable LED output pins to their respective levels.

Secured Music Box – Overview

We have a basic box with a cut out for the door, and an attached handle to open and close the door. There’s a magnetic reed sensor on the frame and a magnet on the door. The reed sensor was attached to an A3BU pin that outputs whether the circuit is open or closed, when closed the red LED comes on, and the A3BU LCD says either “Box Status Opened” or “Box Status Closed”. When the pin reads that the box is opened, the green LED lights up, and the buzzer then also starts to sound off. We originally had a 20 sided die that was glued to the front of the box, but the glue was not enough to hold it as securely as we needed. We ended up replacing it with a cardboard handle and used duct tape to make it stay in place. The door handle is much more secure now as a result. Next we assembled the LEDs with accompanying 100Ω resisters, each one was connected to the assigned pin we had picked out in the code, and then connected them to ground. The buzzer was also put in place, but assigned its own pin so it could operate independently and therefore create the assigned sounds without effecting the light coming from the red LED. The reed sensor and magnetic strip was taped in place so that the magnetic strip would stay with the door, and the sensor would stay in place.

Secured Music Box

The design for our project included a reed switch in the form of a magnetic sensor, three different colored LEDs, a buzzer, and a code input. We started with a cardboard box, which we added a door to, and then attached the magnetic sensor to the door so that when the door is closed, current flows to the yellow LED, and when the door is opened the current is broken, which a pin on the A3BU will detect. When that pin is triggered, two pins will go high and send current to a red LED and a buzzer. If a code is then entered, the two pins that were turned on will be sent low, and a new pin will be sent high to make a green LED  turn on instead. When the door is closed, the yellow LED should turn back on, and all other pins should be low.