OK Students! Time to take everything you've learned and put it together into a final project.
Your homework for tonight is to come up with the topic for your final project and then bring it in to show tomorrow to the rest of the students.
While walking home from school, you nearly walk right into Skrillex!
"Wow," you say. "It's the famous American electronic music producer and DJ Skrillex"
"That's right," he replies. "It is a pleasure to meet you"
You apologize for almost bumping into him: "Sorry for being so distracted...I'm just thinking of what I should do for my electronics class lesson project. But all I know is how to blink an LED!"
"You know how to blink an LED?" Skrillex is impressed! "Maybe you can help me with a problem I have, and it could also be your lesson project..."
Photo Credit: Michael Nusbaum, www.mikenusbaum.com
Skrillex is known for making electronic music in the Dubstep genre. This music has a tempo of 140 beats per minute (bpm). Your lesson project will help out a dubstep musician by pulsing an LED at about 140 bpm. (It is OK if your tempo is off by a little, just make sure it is within half a bpm)
What code sketch should you upload to your Arduino?
Hint: Remember that the LED on and off time together count as one beat.
Here's one way to look at building this project (But we really do suggest trying to write the code on your own!)
Lets work out the delays necessary to have the LED blink 140 times per minute.
140 bpm is the same as 140 / 60 = 2.3333... beats per second.
But we dont want beats-per-second we want seconds-per-beat so flip it around: 1/2.3333 = 0.428 second per beat. That is the same as 428 milliseconds
As the hint hinted, you need to have the LED on for half that time, and off for half. So the delay between each digitalWrite has to be 428/2 = 214 milliseconds.
Change both delay statements to delay(214);
Working backwards, 214 milliseconds * 2 = 428 milliseconds per beat or 0.428 seconds
60/0.428 = 140.1869 bpm, which is close enough!