<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>iSerendipity &#187; code</title>
	<atom:link href="http://iserendipity.elusiveness.org/tag/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://iserendipity.elusiveness.org</link>
	<description>Embedded Interaction</description>
	<lastBuildDate>Mon, 13 Apr 2009 06:02:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Basic Stamp Programming</title>
		<link>http://iserendipity.elusiveness.org/2009/04/basic-stamp-programming/</link>
		<comments>http://iserendipity.elusiveness.org/2009/04/basic-stamp-programming/#comments</comments>
		<pubDate>Wed, 01 Apr 2009 19:17:38 +0000</pubDate>
		<dc:creator>Michelle</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[basic stamp]]></category>
		<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://iserendipity.elusiveness.org/?p=231</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<p>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.</p>
<blockquote><p> </p>
<pre>' {$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</pre>
</blockquote>
<p> </p>
<p>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.</p>
<p> </p>
<pre>' {$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&gt;=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&gt;=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&gt;=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&gt;=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</pre>
]]></content:encoded>
			<wfw:commentRss>http://iserendipity.elusiveness.org/2009/04/basic-stamp-programming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

