[C.CC USERS] occam-pi syntax question

Dennis Meade meade.dennis at gmail.com
Wed Apr 28 01:03:33 BST 2010


Hi, everyone

I've read the explanation of how to continue a line, but I just don't 
seem to get something. I understood that you could continue a line if 
the line ends in one of a number of characters. This is from the occaam 
2.1 Refence Manual. Below is an example of a function call that the 
compiler rejects. So, what did I do wrong? Notice, I broke broke up a 
calculation in the first FUNCTION to get it past the compiler.

The complete code is at the bottom.

     :        ALT
     :          degrees ? current.degrees
     :            pulse := degrees.to.pulse ( current.degrees,
     :            min.degrees, max.degrees, min.pulse, max.pulse )
   53:            reset := TRUE
-----------------^
     :          time ? AFTER begin.time PLUS refresh.time
     :            reset := TRUE
     :        IF
     :          reset

Error-occ21-servo.module(53)- incorrect indentation

***** servo.module   ************************************************

#IF NOT (DEFINED (SERVO.MODULE))
#DEFINE SERVO.MODULE
#ENDIF

#INCLUDE "wiring.module"

VAL INT min.pulse IS 900 :     -- Minimum servo position
VAL INT max.pulse IS 2100 :    -- Maximum servo position

VAL INT min.degrees IS 0 :
VAL INT max.degrees IS 180 :

VAL INT refresh.time IS 20 :   -- the time needed in between pulses

INT FUNCTION degrees.to.pulse ( VAL INT degrees.in, degrees.low, 
degrees.high, milliseconds.low, milliseconds.high )
   INT pulse.in.milliseconds :
   INT x1, x2, x3, x4 :
   VALOF
     SEQ
       x1 := ( degrees.in - degrees.low )
       x2 := ( milliseconds.high - milliseconds.low )
       x3 := ( degrees.high - degrees.low )
       x4 := milliseconds.low
       x4 :=  x1 * (x2 / x3)
       pulse.in.milliseconds := x4 + milliseconds.low
     RESULT pulse.in.milliseconds
:

PROC servo (VAL INT servo.pin, CHAN INT degrees ? )

   INT begin.time :
   INT current.degrees :
   INT pulse :                -- Amount to pulse the servo
   TIMER time :
   BOOL reset :

   SEQ

     current.degrees := 0
     pulse := min.pulse             -- Set the initial motor position
     pinMode(servo.pin, OUTPUT)     -- Set servo pin as an output pin

     time ? begin.time
     reset := FALSE

     WHILE TRUE
       SEQ
         ALT
           degrees ? current.degrees
             pulse := degrees.to.pulse ( current.degrees,
             min.degrees, max.degrees, min.pulse, max.pulse )
             reset := TRUE
           time ? AFTER begin.time PLUS refresh.time
             reset := TRUE
         IF
           reset
             SEQ
               digitalWrite(servo.pin, HIGH)   -- Turn the motor on
               delay(pulse)                    -- Length of the pulse
               digitalWrite(servo.pin, LOW)    -- Turn the motor off
               time ? begin.time
               reset := FALSE
:

-- 
Dennis





More information about the users mailing list