In a previous lesson, you saw how to
read the status of a push-button switch. The result was either a 0
or a 1. In still another lesson, you were
introduced to the concept of a histogram. Let's combine the two
in this lesson, to learn more about histograms in the context of
analyzing some real data.
Wire up the circuit shown below, then run the following code. Press the button as fast as you can, 10 times. What do you see as the output?
Move the mouse over a dotted box for more information.
timedigitalchange will allow you to precisely time how long it takes you to press (then release) the push button switch. This time
is to be histogrammed. Start with the default code to see how this timing works. When done, paste in and run the "histogram" code below to handle the
Now you try. Understand how timedigitalchange works, then histogram 100 of your presses.
Type your code here:
See your results here:
println("Go! Click the switch as fast as you can, 100 times.")
for i=1,100 do
x = timedigitalchange(2)
What does your histogram look like with a bucket size of 5 ms? 10 ms? 50 ms? Do you understand the importance of the bucket size with histograms?
With a bucket size of 5 ms, do a 'serious' run, pressing the button as fast as you can 100 times. What are your thoughts on the resulting histogram?
Share your code
Show a friend, family member, or teacher what you've done!