Basic Stamp Programming
by Michelle on Apr.02, 2009
Below is our initial code for controlling the motor to move the pods in addition to sensing a switch press to turn on LED lights for a few seconds. However, this only worked for sensing one switch at a time since keeping the program in a loop as a counter would prevent the program from monitoring other switches simultaneously.
' {$STAMP BS2} counter VAR Word speed VAR Word speed = 757 OUTPUT 0 OUTPUT 1 OUTPUT 12 INPUT 14 INPUT 15 start: 'motor rotation PULSOUT 12, speed PAUSE 20 OUT0 = 0 'turn LED off IF IN15 = 1 THEN led_1_on 'switched on OUT1 = 0 'turn LED off IF IN14 = 1 THEN led_2_on 'switched on GOTO start led_1_on: 'keep light on for a few seconds FOR counter = 1 TO 75 'continue the motor pulse PULSOUT 12, speed PAUSE 20 'turn on the LED OUT0 = 1 NEXT RETURN led_2_on: 'keep light on for a few seconds FOR counter = 1 TO 75 'continue the motor pulse PULSOUT 12, speed PAUSE 20 'turn on the LED OUT1 = 1 NEXT RETURN
Since we will have 3 pods circulating the track and hitting switches along their paths continuously, we had to find a different method that eliminated loops and kept seperate incremental counters.
' {$STAMP BS2}
led1On VAR Word
led2On VAR Word
led3On VAR Word
led4On VAR Word
led1TimeCount VAR Word
led2TimeCount VAR Word
led3TimeCount VAR Word
led4TimeCount VAR Word
ledOnLength VAR Word
motorSpeed VAR Word
INPUT 1
INPUT 2
INPUT 3
INPUT 4
OUTPUT 7 'green
OUTPUT 8 'blue
OUTPUT 9 'red
OUTPUT 10 'green
OUTPUT 12
start:
led1On = 0
led2On = 0
led3On = 0
led4On = 0
led1TimeCount = 0
led2TimeCount = 0
led3TimeCount = 0
led4TimeCount = 0
ledOnLength = 20
motorSpeed = 755 '750 = stop
GOTO main1
main1:
PULSOUT 12, motorSpeed
PAUSE 20
IF led1TimeCount>=ledOnLength THEN led1_off
IF led1On=1 THEN led1_add
IF IN1=1 THEN led1_on
GOTO main2:
main2:
PULSOUT 12, motorSpeed
PAUSE 20
IF led2TimeCount>=ledOnLength THEN led2_off
IF led2On=1 THEN led2_add
IF IN2=1 THEN led2_on
GOTO main3:
main3:
PULSOUT 12, motorSpeed
PAUSE 20
IF led3TimeCount>=ledOnLength THEN led3_off
IF led3On=1 THEN led3_add
IF IN3=1 THEN led3_on
GOTO main4:
main4:
PULSOUT 12, motorSpeed
PAUSE 20
IF led4TimeCount>=ledOnLength THEN led4_off
IF led4On=1 THEN led4_add
IF IN4=1 THEN led4_on
GOTO main1:
led1_on:
led1On = 1
GOTO main2
led1_add:
OUT8 = 1
led1TimeCount = led1TimeCount + 1
GOTO main2
led1_off:
OUT8 = 0
led1TimeCount = 0
led1On = 0
GOTO main2
led2_on:
led2On = 1
GOTO main3
led2_add:
OUT9 = 1
led2TimeCount = led2TimeCount + 1
GOTO main3
led2_off:
OUT9 = 0
led2TimeCount = 0
led2On = 0
GOTO main3
led3_on:
led3On = 1
GOTO main4
led3_add:
OUT10 = 1
led3TimeCount = led3TimeCount + 1
GOTO main4
led3_off:
OUT10 = 0
led3TimeCount = 0
led3On = 0
GOTO main4
led4_on:
led4On = 1
GOTO main1
led4_add:
OUT7 = 1
led4TimeCount = led4TimeCount + 1
GOTO main1
led4_off:
OUT7 = 0
led4TimeCount = 0
led4On = 0
GOTO main1
June 26th, 2010 on 3:42 am
Pillspot.org. Canadian Health&Care.Special Internet Prices.No prescription online pharmacy.Pillspot.org. Herbal-supplements@buy.online” rel=”nofollow”>.…
Categories: Anxiety/Sleep Aid.Vitamins/Herbal Supplements.Anti-allergic/Asthma.Weight Loss.Antidepressants.Pain Relief.Eye Care.Antiviral.Blood Pressure/Heart.Mental HealthAntidiabetic.Skin Care.Womens Health.Antibiotics.Stop SmokingStomach.Mens H…