including range class
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.
And that in the Projects folder.
I don't get it, it should work, or not?
Any idea's?
Thanks
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
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