Hm55b
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
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
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