HB-25 SPIN Question
NWCCTV
Posts: 3,629
I am anxiously awaiting the arrival of my Wild Thumper robot which will be here tomorrow. While I am waiting I am working on getting my SPIN code for the IR Remote to work with it. It comes with 2 Ea. HB-25's. Several months ago I wrote the code for 2 HB-25's to work using Parallax IR receiver and a standard remote control for another project using PBasic. In PBasic, you must issue a pause 1 command immediately after the first PULSEOUT command to start the second HB-25. Do I do the same thing in SPIN? PBasic code example below.
IF (IN3 = 1) THEN ' Checks if Pushbutton on IN3 is pressed,
' If Yes then send pulseout command to Pin
PULSOUT HB25, 500 ' 15 to rotate motor 1 forward.
PAUSE 1 ' 1 mS Delay For Motor 2 Pulse
PULSOUT HB25, 1000 ' send pulsout command to pin 15
' to rotate motor 2 reverse.
PAUSE 10 ' wait 10 ms

Comments
pub pulse_out(pin, us) '' Creates active-high pulse output on pin (timing in microseconds) '' -- leaves pin a output low us *= (clkfreq / 1_000_000) ' convert to ticks phsa := 0 frqa := 1 ctra := (%00100 << 26) | pin ' NCE/SE mode dira[pin] := 1 ' make pin an output phsa := -us ' start the pulse waitpne(1 << pin, 1 << pin, 0) ' let it finish pub pause(ms) | t '' Delay program in milliseconds if (ms < 1) ' delay must be > 0 return else t := cnt - 1776 ' sync with system counter repeat ms ' run delay waitcnt(t += (clkfreq / 1000))Converting your PBASIC fragment:
if (ina[3] == 1) pulse_out(HB25, 1000) pause(1) pulse_out(HB25, 2000) pause(10)Remember that BS2 PULSOUT units are 2us each; the pulse_out() method uses 1us units, hence the change in the values.