Basic Sensor Board

Explanation
Basic code to use the O.A.R. Sensors Board.
We know that the sensor is going to write a logic 0 when it sees black. Therefore using a simple if statement inside a loop we can make the robot follow a black line until it loses it. An LED will be switched on when a black line is seen by the sensor. When the robot goes off the black line the robot will stop the motors and will turn off the LED. For this program we are going to connect the sensor in PORT7 and an LED in PORT9.

' {$STAMP BS2}
' {$PBASIC 2.5}

irsensor VAR Bit 'Variable to store the information from the sensor

DO
   irsensor = IN7 'Read the port. The sensor is plugged into PORT7

   IF (irsensor = 0) THEN 'If the sensor reads black
      HIGH 9 'Turn on the LED
      PULSOUT 12, 700 'Turn on motors to move the robot forward
      PULSOUT 13, 800
   ELSE 'If the sensor reads white, I.e. irsensor = 1
      LOW 9 'Turn off LED
      'Doing nothing else the robot will not move
   ENDIF
LOOP
page_revision: 1, last_edited: 1209603271|%e %b %Y, %H:%M %Z (%O ago)
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License