Shop OBEX P1 Docs P2 Docs Learn Events
including range class — Parallax Forums

including range class

Robot FreakRobot Freak Posts: 168
edited 2006-12-06 20:40 in General Discussion
I have done two things: first I tryed th following code with an include, that didn't work, so I placed the whole package in the main file, and that worked!
So, I'm doing something wrong with the including.
I've placed in the folder lib\stamp\peripheral\sensor\range the class SRF04.
import stamp.core.*;

public class Ping {

  public static final char HOME = 0x01;

  public static void main() {
    Ping range = new Ping(CPU.pin0);
    StringBuffer msg = new StringBuffer();
    int distance;
    while (true) {
      // measure distance to target in inches
      distance = range.getCm();
      // create and display measurement message
      msg.clear();
      msg.append(HOME);
      msg.append(distance);
      msg.append(" \" \n");
      System.out.print(msg.toString());
      // wait 0.5 seconds between readings
      CPU.delay(500);
    }
  }
}


And that in the Projects folder.
I don't get it, it should work, or not?

Any idea's?
Thanks

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-12-06 20:40
    If you have put the class Ping.java in folder .../sensor/range/ping/ then

    import·stamp.core.*;
    import stamp.peripheral.sensor.range.ping.*;· //you need this to use Ping class

    public·class·Ping_test·{ //this class is the application program, save as Ping_test

    ··public·static·final·char·HOME·=·0x01;

    ··public·static·void·main()·{
    ····Ping·range·=·new·Ping(CPU.pin0);
    ····StringBuffer·msg·=·new·StringBuffer();
    ····int·distance;
    ····while·(true)·{
    ······//·measure·distance·to·target·in·inches
    ······distance·=·range.getCm();
    ······//·create·and·display·measurement·message
    ······msg.clear();
    ······msg.append(HOME);
    ······msg.append(distance);
    ······msg.append("·\"·\n");
    ······System.out.print(msg.toString());
    ······//·wait·0.5·seconds·between·readings
    ······CPU.delay(5250); //value 105 equals 10 msec, so for 500 msec the value is 5250
    ····}
    ··}
    }

    should work.

    I guess you forgot to import ping folder.

    regards peter
Sign In or Register to comment.