Period of oscillation of a pendulum can be measured by allowing it to intercept a beam of light falling on a photo-transistor. The LED is powered by SQR1 and the photo-transistor collector is connected to SEN, which goes to the internal analog comparator of the micro-controller. Oscillate the pendulum and measure the time period between alternate interceptions, count only for one direction.
import expeyes.eyesj, sys
p = expeyes.eyesj.open()
p.set_sqr1(0) # set SQR1 HIGH to light LED
for k in range(10):
print p.multi_r2rtime(0,1) # Rising edge to rising edge on comparator output, skip one edge in between
Acceleration due to gravity can be calculated from the period measured. Since we have used a rod pendulum, the relation
is g = 4 * pi * pi * L / (T*T) = 4*pi**2*15.4/.6432**2*2/3 = 979.7
Don't get exited with the accuracy of the result. It might have come closer to the actual value due to the error in measuring the length. What really maters is the small spread in the measured value. The frequency change due to large amplitudes can be easily observed.