xo 1.75 accelerometer for pippy

Gabriel Eirea geirea at gmail.com
Mon Sep 5 09:15:17 EDT 2011


Hi:

I'm sending this simple code to test the accelerometer in Pippy. It
tries to reproduce Bert's moving-ball example with ASCII.

Regards,

Gabriel


import pippy
f = open("/sys/devices/platform/lis3lv02d/position",'r')
xn, yn, zn = 0, 0, 0
px, py = 15.0, 15.0
try:
  while 1:
    f.seek(0)
    a = f.read()
    pos = a[1:len(a)-2].split(',')
    xn = int(pos[0]) + .9*xn
    yn = int(pos[1]) + .9*yn
    zn = int(pos[2]) + .9*zn
    x = int(xn/10)
    y = int(yn/10)
    z = int(zn/10)
    pippy.console.clear()
    if x>20 and px<30:
      px += .05
    elif x<-20 and px>0:
      px -= .05
    if y>20 and py<30:
      py += .05
    elif y<-20 and py>0:
      py -= .05
    for l in range(int(py)):
      print " "
    for c in range(int(px)):
      print " ",
    print "@"
finally:
  f.close()



More information about the Devel mailing list