Recent Changes - Search:

Home

Is the Laser up?

People

Publications

Calendar

Projects

Spring 2012

Older Courses

Fall 2011

Spring 2011

Fall 2010

Spring 2010

Fall 2009

Spring 2009

Fall 2008

Spring 2008

Fall 2007

HOWTOs

edit SideBar

EventsPerInterval

How to Count a Number of Events Per Time Interval

This explain how to use the Cricket to count a number of events per a fixed time interval. This can be used to record a number of steps per minute (e.g., making a pedometer with an inclination sensor that measures steps).

The code assumes the step-measuring sensor is plugged into the sensora port. It will record 10 minutes of activity, sampling your step-count every 10 seconds. (This is a total of 60 samples, one per 10 seconds.)

global [steps]

to main
when [switcha][setsteps steps + 1]
repeat 60 [
  setsteps 0
  wait 100
  record steps]
end

The method is to use the Cricket's when statement which can trigger code that runs in the background. The when statement is used in conjunction with a global variable to accumulate the step count. During the wait 100 statement, the when command is active and accumulates the step count.

You can add a beep statement in the body of the when to help hear how the counts are being recorded.

Edit - History - Print - Recent Changes - Search
Page last modified on October 08, 2006, at 02:54 AM