×

Discussion Board

Results 1 to 3 of 3

Hybrid View

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    22

    Unhappy funky print command behaviour

    I wrote the following code to count steps that I take:

    Code:
    1  import pyextaccel
    2  import appuifw
    3  import e32
    4  
    5  def printout (x,y,z):
    6      global steps
    7      global high
    8      accel = x * x + y * y + z * z
    9      print u""
    10     if accel >= 500000:
    11         if high==0:
    12             steps += 1
    13             steps_str = str(steps)
    14             print u""+steps_str
    15             high=1
    16     else:
    17         high=0
    18      
    19 def quit():
    20     global running
    21     running =0
    22     pyextaccel.unregister()
    23     appuifw.app.set_exit()
    24 
    25 running = 1
    26 steps = 0
    27 appuifw.app.exit_key_handler=quit
    28 while running:
    29     pyextaccel.register(printout)
    30     e32.ao_yield()
    As you can see, line 9 doesn't do anything but print a blank line, but line 14 doesn't work unless line 9 is there. What am I doing wrong?

    Also, if there is code written already for counting steps, could you link me to it?

    Thanks!

  2. #2
    Registered User
    Join Date
    Feb 2005
    Location
    Belgium (Europe)
    Posts
    1,352

    Re: funky print command behaviour

    Quote Originally Posted by hyon View Post
    I wrote the following code to count steps that I take:

    Code:
    1  import pyextaccel
    2  import appuifw
    3  import e32
    4  
    5  def printout (x,y,z):
    6      global steps
    7      global high
    8      accel = x * x + y * y + z * z
    9      print u""
    10     if accel >= 500000:
    11         if high==0:
    12             steps += 1
    13             steps_str = str(steps)
    14             print u""+steps_str
    15             high=1
    16     else:
    17         high=0
    18      
    19 def quit():
    20     global running
    21     running =0
    22     pyextaccel.unregister()
    23     appuifw.app.set_exit()
    24 
    25 running = 1
    26 steps = 0
    27 appuifw.app.exit_key_handler=quit
    28 while running:
    29     pyextaccel.register(printout)
    30     e32.ao_yield()
    As you can see, line 9 doesn't do anything but print a blank line, but line 14 doesn't work unless line 9 is there. What am I doing wrong?

    Also, if there is code written already for counting steps, could you link me to it?

    Thanks!
    Welcome hyon in the fantastic world of accelerometer
    First which device have you used ?
    pyextaccel is for 5500 and for N95 20.X
    axyz works with ANY N95 (not with 5500) It's the only way to use accelerometer with old N95 firmware ...
    sensor is more general and it's prefered way if you use 5500 or N95 20.X (so don't use pyextaccel in this case !)

    Code:
    1  import pyextaccel
    2  import appuifw
    3  import e32
    4  
    5  def printout (x,y,z):
    6      global steps
    7      global high
    8      accel = x * x + y * y + z * z
    9      
    10     if accel >= 500000:
    11         if high==0:
    12             steps += 1
    13
    14             print u"%d"%steps
    15             high=1
    16     else:
    17         high=0
    18      
    19 def quit():
    20
    21
    22     pyextaccel.unregister()
    23     app_lock.signal()
    24 
    25 
    26 steps = high = 0
    27 appuifw.app.exit_key_handler=quit
    28 pyextaccel.register(printout)
    29 app_lock=e32.Ao_lock()
    30 app_lock.wait()
    I have corrected your code

    BR
    Cyke64
    pys60 1.4.5 and 2.0.0, pygame, PyS60 CE on E90 and 5800 !

    Find my pys60 extension modules on cyke64.googlepages.com

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    22

    Re: funky print command behaviour

    Thanks so much for your help - your code does exactly what I wanted it to do.

    I just have a few more questions:

    • How is it that you didn't have to loop anywhere, but it loops?
    • I am using a 5500 and you said I should use "sensor" - what is "sensor"?


    As you can tell, I am not only new at using the accelerometer, but also at coding in Python... again, thanks for your help!

Similar Threads

  1. Python for UIQ
    By cassioli in forum Symbian
    Replies: 141
    Last Post: 2008-06-11, 18:16
  2. Random RingTone within Contact List for 3rd
    By cckfranky in forum Symbian
    Replies: 5
    Last Post: 2007-12-29, 18:33
  3. Replies: 2
    Last Post: 2007-11-15, 18:26
  4. How to send an image with attachment in email
    By krtrivdi in forum Symbian
    Replies: 1
    Last Post: 2007-01-09, 12:07
  5. Sending an image over email
    By jeclarim in forum Symbian
    Replies: 3
    Last Post: 2006-12-15, 20:25

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •