'This Program is the Semaphore project. 'It reads a photocell on pin 1 and drives a servo on pin 0. '-------------------------------------------------------------------------- Output 0 'Sets pin 0 as an output Input 1 'Sets pin 1 as an input 'The following lines define symbols for use as program variables. Symbol Servo_Max = b0 'Servo maximum up position and 'is usually a value between 100 'and 140. Symbol Servo_Mid = b1 'Servo middle position and is 'usually around 150 Symbol Servo_Min = b2 'Servo minimum down position and 'is usually between 160 and 200. '(overall servo is from about 100 'to 200.) Symbol Servo_Pos = b4 'Position servo is driven to. Symbol Timer_Delay = b5 'Value used by both timers as the 'delay time between positions and 'is in tenths of a second. Symbol Threshold = b6 'Value between full light and 'blocked light of the photocell 'and is typically around 120. Symbol Photo_Scale = b7 'Scale value for POT instruction '(see text for details.) Symbol Sensed = b8 'The actual sensed light value 'from the photocell. Symbol Timer_1 = b9 'Timer between down and middle 'positions. Symbol Timer_2 = b10 'Timer betwenn middle and up 'positions. 'The following line are where you should enter your calibration values '(see text for details on each) Let Photo_Scale = 50 'Photocell scale value (see text). Let Threshold = 120 'photocell light threshold. Let Servo_Max = 100 'Max Up Position. Let Servo_Mid = 150 'Mid Position. Let Servo_Min = 200 'Min Down Position. Let Timer_Delay = 50 'Delay in tenths. Start: 'Start of the main program. 'On initial startup, the following two lines will drive the servo 'to an initial position. Let Servo_Pos = Servo_Min 'Servo startup position. Gosub Servo 'Go to servo subroutine. 'This is the main loop of the program. Loop: Gosub Sensor 'Goes to read photocell If Sensed < Threshold Then Loop 'Is photocell light blocked? '(if not continue at "loop".) 'This is where the program drives the servo to the down position and starts 'timer1, once the photocell value is less than the threshold value. '(If anytime during the timing process the photocell threshold is crossed, 'this down process will start all over again.) Down: Let Servo_Pos = Servo_Max 'Set servo to down position. Gosub Servo 'Go to servo Subroutine. For Timer_1 = 1 to Timer_Delay 'Start timer 1. Gosub Sensor 'Read photocell. If Sensed > Threshold Then Down 'Is photocell light blocked? Pause 100 'A tenth of a second pause for the timer. Next Timer_1 '(companion instruction for timer 1.) 'This is where the program drives the servo to the middle position and 'starts timer2. '(if anytime during the timing process the photocell threshold is crossed, 'the down sequence will start all over again.) mid: Let Servo_Pos = Servo_Mid 'Set servo to the middle position. Gosub Servo 'Go to servo subroutine. For Timer_2 = 1 to Timer_Delay 'Start timer 2. Gosub Sensor 'Read photocell If Sensed > threshold Then Down 'Is photocell light blocked. Pause 100 'A tenth of a second pause for the timer. Next Timer_2 '(companion instruction for timer 2.) 'This is where the program drives the servo to the up position. up: Let Servo_Pos = Servo_Min 'Set servo to up position. Gosub Servo 'Go to servo subroutine. Goto Loop 'Start loop all over again. End 'This is the servo subroutine Servo: For b3 = 1 to 20 Pulsout 0,Servo_Pos Pause 30 Next b3 Return 'This is the photocell sensor subroutine Sensor: Pot 1,Photo_Scale,Sensed Return