'Mars MAE Basic Stamp program - RG 9911.03 - 0403.23 'for SERVO magazine article 'Stamp 1 program for reading a CdS photosensor, driving 'a Muscle Wire lever arm, calculating results and sending 'them to an LCD display at 2400 baud with backlight control 'set Input/Output directions output 0 'Yel LED output output 1 'Grn LED output input 2 'Button 1 input input 3 'Button 2 input output 4 'MW output output 5 'LCD display input 6 'CdS Sensor input w0 = 255 w1 = 255 w2 = 255 symbol i = w4 'counter i 'setup LCD display pause 1000 serout 5, N2400, (12) 'clear LCD screen serout 5,N2400,(" ",2," Mars Dust Level ",3,13) '2=inverse, 3=normal GOTO display 'put up rest of text 'Program loop loop1: IF pin2 = 1 THEN skip1 'if button 1 not pressed then skip gosub GOSUB LCDonoff 'if button 1 pressed, go toggle LCD & LED skip1: pin0 = 1 'Yellow LED ON pwm 4, 150, 200 'activate Muscle Wire (pin, power, time ms) pwm 4, 30, 100 'hold open (pin, pwer, time ms) pin0 = 0 'Yellow LED OFF 'check BRIGHT light level pot 6, 75, w0 'read port 6, store in word 0 w2 = w1 - w0 'update the difference pin4 = 0 'turn Muscle Wire off FOR i = 1 TO 3500 'wait for Muscle Wire to relax IF pin2 = 1 THEN skip2 'if button 1 not pressed then skip gosub GOSUB LCDonoff 'if button 1 pressed, go toggle LCD & LED skip2: NEXT i 'check DARK light level again pot 6, 75, w1 'read port 6, store in word 1 w2 = w1 - w0 'and update the difference display: serout 5,N2400,(16,#21," Bright: ",#w0," ",13) '13 is CR serout 5,N2400,(" Dark: ",#w1," ",13) '13 is CR serout 5,N2400,("Difference: ",#w2," ",13) '13 is CR GOTO loop1 '***** SUBROUTINES LCDonoff: IF pin1 = 1 THEN lcdoff 'if green LED ON then go turn OFF serout 5, N2400, (14) 'turn LCD backlight ON pin1 = 1 'turn green LED ON goto wait lcdoff: serout 5, N2400, (15) 'turn LCD backlight OFF pin1 = 0 'turn green LED OFF wait: if pin2 = 0 then wait 'wait for button up pause 10 RETURN