Lesson goal: Study your button pushing reaction

Previous: Read a push-button switch | Home

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?

timedigitalchange(pin)
set_bucket_size(size)
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 histogramming.

Now you try. Understand how timedigitalchange works, then histogram 100 of your presses.

Type your code here:


See your results here:

Histogram Code
new_chart('time','count','histogram')
set_bucket_size(5)

println("Go! Click the switch as fast as you can, 100 times.")

for i=1,100 do
 x = timedigitalchange(2)
 histogram_point(x)
end

Circuit

Results 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?

Dismiss.
Show a friend, family member, or teacher what you've done!

Here is a share link to your code:

Does your code work? Want to run it on your iPhone?

Here's your code:

  1. Use [Control]-[C] (Windows) or [⌘]-[C] (MacOS) to copy your code.

  2. Paste it using [Control]-[V] (Windows) or [⌘]-[V] (MacOS) into this page

  3. Then click the "Use on iPhone" button that you'll see.