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

ReactionTime

Here is an example application which creates a reaction game. The Cricket will randomly beep, and you have to hit a switch as soon as you can after you hear the beep. The Cricket then measures the delay between the beep and your reaction.

The Cricket's 4-digit display is used. After each try, your delay score is shown on the display.

In the example, you are given ten tries, and the Cricket displays your average performance at the end.

The random function is used. This produces a randomized value from 0 to 32767. It is used in conjunction with the remainder/modulus operator to produce a random value between 0 and 39.

global [delay total]

to reaction
settotal 0
repeat 10 [
  wait 10 + (random % 40)  ; wait from 1 to 5 seconds
  resett
  beep
  waituntil [switcha]
  setdelay timer
  display delay
  settotal total + delay
]
display total / 10
end

to display :n
bsend $110 bsend 0
bsend high-byte :n 
bsend low-byte :n
end
Edit - History - Print - Recent Changes - Search
Page last modified on October 08, 2006, at 04:56 AM