Remember to set the
Remember to set the direction of the pin to input or output first like:
dira[pin_number]~~
then set it to a high like:
outa[pin_number]~~
You can also do it in just one line of code like:
outa[pin] := dira[pin] := 1
As for the PING))) sensor, that should be simple using the object from the OBEX. Download the object called “PING)) Demo” and extract it from zip file to where you are working on your other objects. All you have to do is declare it in your program and then call it to your variable like this:
OBJ
pg : “ping” 'Declare the PING object with the Alias of "pg"
CON
pin = 0 'Set my pin for the Ping
VAR
long useconds, inches, centimeters, millimeters ’ Setup variables that store the results
PUB GetDistance
useconds := pg.Ticks(pin) ’ Get ms reading and assign that to the VARiable “useconds”
waitcnt(cklfreq + cnt) ’ wait one second just (because I want to)
inches := pg.Inches(pin) ’ get distance in inches and assign that to the VAR of “inches”
waitcnt(cklfreq + cnt) ’ wait one second just (because I want to)
centimeters := pg.Centimeters(pin) ’ The VAR “centimeters” now holds the distance in centimeters
waitcnt(cklfreq + cnt) ’ wait one second just (because I want to)
millimeters := pg.millimeters(pin) ’ same as above the “millimeters” VAR holds the distance in mm
The coding is fairly strait forward by looking at the PING.spin object. Remeber that you do not have to look at all the lines of code in an object’s PUB routine to use it. For example:
PUB Millimeters(Pin) : Distance
The name after the PUB statement is what you call from your own object with the options in parenthesis (pin).