Post by KittyWolf on Feb 16, 2016 6:09:54 GMT
Assignment #2 - Science Fiction Movie Prop
In this assignment you will use the PwmOut interface on the mbed microcontroller board to implement a low-budget science fiction movie ("Dawn of the Mbeds") prop that has blinking LEDs and sound effects.
Connect the piezo transducer (it looks like a small black cylinder with a hole at the top to emit sound) between the mbed's p22 and GND. Connect two pushbutton switches, one between the mbed's p30 and VOUT and another between p28 and VOUT.
The mbed should start in an idle mode in which all of the LEDs are off and the piezo transducer is silent. If either switch is pressed, the mbed begins one of two different effects, one effect for each switch. When no effects are active, the mbed should return to the idle mode.
If the switch connected to p30 is pressed, the mbed should generate a "pew-pew" laser effect and repeat the effect until the switch is released. During this effect the piezo transducer should generate a decending frequency from 1600 Hz to 800 Hz at maximum volume over the span of roughly 0.2 - 0.4 seconds (user whatever timing within this range that sounds good to you). Synchronized with this sound effect, the 4 built-in LEDs should change their brightness according to the current piezo frequency, with a peak frequency at which the LED is at maximum brightness. As the distance between the current and peak frequency increases, the LED get progressively dimmer. LED1 should peak at 1500 Hz, LED2 at 1300 Hz, LED3 at 1100 Hz, and LED4 at 900 Hz. The overall result is a "laser pulse" moving through the 4 LEDs. A simple way to calculate the brightness for each LED is the equation
If the switch connected to p28 is pressed, the mbed should continuously play random ominous notes through the piezo that fade in while one of the 4 built-in-LEDs also fades on and off. Each note should be selected with a random frequency between 500 Hz and 1000 Hz. Over the span of 1 - 2 seconds, the piezo transducer's duty cycle should increase from 0% to 5%, causing the volume to subtly increase from silent to audible. During this same time span, the randomly selected LED should transition from fully off to fully on and then back to fully off (so it is at peak brightness when the piezo is at 2.5% duty cycle). This effect should only stop if the switch connected to p30 is pressed (which would switch to the laser effect).
The C function rand() will return a random non-negative integer. Use the expression (rand() / (float) RAND_MAX) if you want a random float in the range 0 to 1.
Connect the piezo transducer (it looks like a small black cylinder with a hole at the top to emit sound) between the mbed's p22 and GND. Connect two pushbutton switches, one between the mbed's p30 and VOUT and another between p28 and VOUT.
The mbed should start in an idle mode in which all of the LEDs are off and the piezo transducer is silent. If either switch is pressed, the mbed begins one of two different effects, one effect for each switch. When no effects are active, the mbed should return to the idle mode.
If the switch connected to p30 is pressed, the mbed should generate a "pew-pew" laser effect and repeat the effect until the switch is released. During this effect the piezo transducer should generate a decending frequency from 1600 Hz to 800 Hz at maximum volume over the span of roughly 0.2 - 0.4 seconds (user whatever timing within this range that sounds good to you). Synchronized with this sound effect, the 4 built-in LEDs should change their brightness according to the current piezo frequency, with a peak frequency at which the LED is at maximum brightness. As the distance between the current and peak frequency increases, the LED get progressively dimmer. LED1 should peak at 1500 Hz, LED2 at 1300 Hz, LED3 at 1100 Hz, and LED4 at 900 Hz. The overall result is a "laser pulse" moving through the 4 LEDs. A simple way to calculate the brightness for each LED is the equation
If the switch connected to p28 is pressed, the mbed should continuously play random ominous notes through the piezo that fade in while one of the 4 built-in-LEDs also fades on and off. Each note should be selected with a random frequency between 500 Hz and 1000 Hz. Over the span of 1 - 2 seconds, the piezo transducer's duty cycle should increase from 0% to 5%, causing the volume to subtly increase from silent to audible. During this same time span, the randomly selected LED should transition from fully off to fully on and then back to fully off (so it is at peak brightness when the piezo is at 2.5% duty cycle). This effect should only stop if the switch connected to p30 is pressed (which would switch to the laser effect).
The C function rand() will return a random non-negative integer. Use the expression (rand() / (float) RAND_MAX) if you want a random float in the range 0 to 1.