My first try at Scribbler2 code outside the GUI
Even though I don't have the Scribbler2 yet (have one on pre-order), I was playing with the S2 object. This is a very crude attempt at using the s2 object and I am only using the S2's fault sensors, wheel motors and obstacle detector for an ir receiver, it compiles ok - maybe Phil could comment on this?
Con
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
speed = 100
Var
long FMStack[50]
byte irc, self
Obj
ir : "irtest"
s2 : "s2"
Pub main
ir.start(23, @irc)
s2.start
s2.start_motors
self := cogid
cognew(FaultMonitor, @FMStack)
repeat
if irc == 51 'left
s2.wheels_now(speed - 100, speed, 1)
if irc == 52 'right
s2.wheels_now(speed, speed -100, 1)
if irc == 116 'foward
s2.wheels_now(speed, speed, 1)
if irc == 117 'reverse
s2.wheels_now(-speed, -speed, 1)
if irc == 255 'stop
s2.stop_now
PUB FaultMonitor : value
value := $ffff
waitcnt(cnt + 80_000_000)
repeat
value <#= s2.get_adc_results(s2#ADC_VBAT)
if value > constant((700*2550)/(400*33)) '7.0V
s2.set_led(s2#POWER,s2#BLUE)
elseif value > constant((600*2550)/(400*33)) '6.0V
s2.set_led(s2#POWER,$20)
else
s2.set_led(s2#POWER,s2#BLINK_BLUE)
if s2.get_adc_results(s2#ADC_IMOT) > 210
cogstop(Self)
s2.stop_now
s2.set_leds(s2#BLINK_RED,s2#BLINK_RED,s2#BLINK_RED,s2#OFF)
repeat


Comments
You were citing the wrong pin; plus, using the constant provided is better coding style.
-Phil