Shop OBEX P1 Docs P2 Docs Learn Events
Hm55b — Parallax Forums

Hm55b

SouLJahSouLJah Posts: 35
edited 2006-11-29 00:18 in General Discussion
Hello, I·have a·HM55B compass, and I created a test class for the provided HM5BB class and I designed the class·to display the angle·readings on the screen, but after a couple of readings I get an out of memory error, could anyone tell me why that happends and if it can be corrected??

btw: When I call the "get angle", "x" and "y" method, BUT only print the x and y on screen·(although i call get angle method), it doesn't give me this error

Thanks

SouLJaH

Here is my code:

import stamp.peripheral.sensor.compass.HM55B;
import stamp.core.*;

public class Compass{

//define the compass pins
static final int cp1_DinDout = CPU.pin0;
static final int cp1_Clk = CPU.pin1;
static final int cp1_En = CPU.pin2;

//define your compass
static HM55B cp1 = new HM55B(cp1_DinDout,cp1_Clk,cp1_En);

public static void main(){

while (true){

cp1.start(); //Start a measurement

if (cp1.poll()==true)

·{

·System.out.println("x = "+ cp1.getCompassX() );
·System.out.println("y = "+ cp1.getCompassY() );
·System.out.println("angle = "+ cp1.getCompassAngle() );
·CPU.delay(1000);

·}//end if
}//end while

·}//end main
·}//end class

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-11-28 19:07
    You should not use + to concatenate strings as this
    creates temporary strings. These strings are only used once and
    since the javelin has no garbage collection, their space is wasted.
    If you use it inside a loop as you do, you eventually will get
    an out of memory error.
    Instead, do
    ·System.out.print("x = ");
    ·System.out.println(cp1.getCompassX() );
    ·System.out.print("y = ");
    ·System.out.println(cp1.getCompassY() );
    ·System.out.print("angle = ");
    ·System.out.println(cp1.getCompassAngle() );

    regards peter
  • SouLJahSouLJah Posts: 35
    edited 2006-11-29 00:18
    Dang, now I understand no garbage collection, thanks for your help [noparse]:)[/noparse]
Sign In or Register to comment.