In SX Microcontrollers, SX/B Compiler and SX-Key Tool, Matthias09 wrote: Hi Beau, thank you very much for the extensive information. I understand the function of the code, however, have problems with implementing it into SX Basic. Main point: The databuffer is always 0. Here is what I've build: US_Black PIN RC.6 'black labeled Ultrasonic sensor ball_position_2 VAR Word 'ball position 2 DataBuffer var word avg var word samples var byte samples = 10 FOR i = 1 TO samples US_Black = 0 'set port to low PULSOUT US_Black, 5 PAUSEUS 100 PULSIN US_Black, 1, ball_position_2 IF i = 1 THEN 'at first reading, initialize the variables Avg = ball_position_2 DataBuffer = Avg * Samples ENDIF DataBuffer = DataBuffer - Avg DataBuffer = DataBuffer + ball_position_2 Avg = DataBuffer / Samples NEXT Do you have any idea? :) Matthias ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=175860#m385329 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2009 (http://www.dotNetBB.com)