<?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>Assignment 2 &#8211; Making Things Interactive</title>
	<atom:link href="https://courses.ideate.cmu.edu/48-339/s2018/?feed=rss2&#038;cat=9" rel="self" type="application/rss+xml" />
	<link>https://courses.ideate.cmu.edu/48-339/s2018</link>
	<description>48-339/739 Spring 2018</description>
	<lastBuildDate>Mon, 12 Mar 2018 16:55:02 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.2.20</generator>
	<item>
		<title>Assignment 2</title>
		<link>https://courses.ideate.cmu.edu/48-339/s2018/?p=296</link>
				<comments>https://courses.ideate.cmu.edu/48-339/s2018/?p=296#respond</comments>
				<pubDate>Thu, 08 Feb 2018 08:13:15 +0000</pubDate>
		<dc:creator><![CDATA[oet@andrew.cmu.edu]]></dc:creator>
				<category><![CDATA[Assignment 2]]></category>

		<guid isPermaLink="false">https://courses.ideate.cmu.edu/48-339/s2018/?p=296</guid>
				<description><![CDATA[It&#8217;s running smoothly, so here it is. I wanted to make a ghost chat which would allow the user to interact with &#8220;ghosts&#8221; that I programmed to be &#8220;detected&#8221; by a photosensor. By pushing the button, the user can ask questions and get an answer. I also initially wanted to program a theme song for &#8230; <a href="https://courses.ideate.cmu.edu/48-339/s2018/?p=296" class="more-link">Continue reading<span class="screen-reader-text"> "Assignment 2"</span></a>]]></description>
								<content:encoded><![CDATA[<p>It&#8217;s running smoothly, so here it is.</p>
<p>I wanted to make a ghost chat which would allow the user to interact with &#8220;ghosts&#8221; that I programmed to be &#8220;detected&#8221; by a photosensor. By pushing the button, the user can ask questions and get an answer. I also initially wanted to program a theme song for each ghost that could run in the background or when someone asks for the ghosts&#8217; favorite song, but that took a backseat when I realized how confused I actually was by interrupts. If I were to really make this perfect, I&#8217;d probably find a different sensor, and figure out a way to have the ghost answer questions that the user defines, as opposed to pre-programmed answers to pre-programmed questions.</p>
<p><img class="alignnone size-medium wp-image-297" src="https://courses.ideate.cmu.edu/48-339/s2018/wp-content/uploads/2018/02/Screen-Shot-2018-02-08-at-1.55.47-AM-300x207.png" alt="" width="300" height="207" srcset="https://courses.ideate.cmu.edu/48-339/s2018/wp-content/uploads/2018/02/Screen-Shot-2018-02-08-at-1.55.47-AM-300x207.png 300w, https://courses.ideate.cmu.edu/48-339/s2018/wp-content/uploads/2018/02/Screen-Shot-2018-02-08-at-1.55.47-AM-768x529.png 768w, https://courses.ideate.cmu.edu/48-339/s2018/wp-content/uploads/2018/02/Screen-Shot-2018-02-08-at-1.55.47-AM-1024x705.png 1024w, https://courses.ideate.cmu.edu/48-339/s2018/wp-content/uploads/2018/02/Screen-Shot-2018-02-08-at-1.55.47-AM-1200x826.png 1200w" sizes="(max-width: 300px) 85vw, 300px" /></p>
<p><a href="https://courses.ideate.cmu.edu/48-339/s2018/wp-content/uploads/2018/02/ghost_chat_a2.zip">ghost_chat_a2</a></p>
]]></content:encoded>
							<wfw:commentRss>https://courses.ideate.cmu.edu/48-339/s2018/?feed=rss2&#038;p=296</wfw:commentRss>
		<slash:comments>0</slash:comments>
							</item>
		<item>
		<title>Assignment 2</title>
		<link>https://courses.ideate.cmu.edu/48-339/s2018/?p=212</link>
				<comments>https://courses.ideate.cmu.edu/48-339/s2018/?p=212#respond</comments>
				<pubDate>Tue, 30 Jan 2018 16:59:55 +0000</pubDate>
		<dc:creator><![CDATA[ctv@andrew.cmu.edu]]></dc:creator>
				<category><![CDATA[Assignment 2]]></category>

		<guid isPermaLink="false">https://courses.ideate.cmu.edu/48-339/s2018/?p=212</guid>
				<description><![CDATA[This project is supposed to be an embodiment of Steve Reich&#8217;s Clapping Music. The code for this project has two versions. The first version works unreliably because it uses the delay function to time the LEDs. The second uses a helper function to time and illuminate the LEDs using millis(). This program does not even &#8230; <a href="https://courses.ideate.cmu.edu/48-339/s2018/?p=212" class="more-link">Continue reading<span class="screen-reader-text"> "Assignment 2"</span></a>]]></description>
								<content:encoded><![CDATA[<p>This project is supposed to be an embodiment of Steve Reich&#8217;s Clapping Music. The code for this project has two versions. The first version works unreliably because it uses the delay function to time the LEDs. The second uses a helper function to time and illuminate the LEDs using millis(). This program does not even finish compiling though. It probably just needs debugging, but I am not sure. With the original program, the interrupt does not reliably switch the case. To continue this project, I will use solenoids to make a percussive sound.</p>
<p><img class="alignnone wp-image-214" src="https://courses.ideate.cmu.edu/48-339/s2018/wp-content/uploads/2018/01/IMG_20180130_115738-225x300.jpg" alt="" width="555" height="740" srcset="https://courses.ideate.cmu.edu/48-339/s2018/wp-content/uploads/2018/01/IMG_20180130_115738-225x300.jpg 225w, https://courses.ideate.cmu.edu/48-339/s2018/wp-content/uploads/2018/01/IMG_20180130_115738-768x1024.jpg 768w, https://courses.ideate.cmu.edu/48-339/s2018/wp-content/uploads/2018/01/IMG_20180130_115738-1200x1600.jpg 1200w" sizes="(max-width: 555px) 85vw, 555px" /></p>
<div style="width: 840px;" class="wp-video"><!--[if lt IE 9]><script>document.createElement('video');</script><![endif]-->
<video class="wp-video-shortcode" id="video-212-1" width="840" height="473" preload="metadata" controls="controls"><source type="video/mp4" src="https://courses.ideate.cmu.edu/48-339/s2018/wp-content/uploads/2018/01/VID_20180130_115938.mp4?_=1" /><a href="https://courses.ideate.cmu.edu/48-339/s2018/wp-content/uploads/2018/01/VID_20180130_115938.mp4">https://courses.ideate.cmu.edu/48-339/s2018/wp-content/uploads/2018/01/VID_20180130_115938.mp4</a></video></div>
<p>&nbsp;</p>
<p><a href="https://courses.ideate.cmu.edu/48-339/s2018/wp-content/uploads/2018/01/vandezandeStateMachineInterrupt.zip">vandezandeStateMachineInterrupt</a></p>
<p>&nbsp;</p>
<p><iframe width="840" height="473" src="https://www.youtube.com/embed/lzkOFJMI5i8?feature=oembed" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe></p>
<p><img class="alignnone wp-image-218" src="https://courses.ideate.cmu.edu/48-339/s2018/wp-content/uploads/2018/01/Screen-Shot-2018-01-30-at-12.29.04-PM-300x189.png" alt="" width="625" height="394" srcset="https://courses.ideate.cmu.edu/48-339/s2018/wp-content/uploads/2018/01/Screen-Shot-2018-01-30-at-12.29.04-PM-300x189.png 300w, https://courses.ideate.cmu.edu/48-339/s2018/wp-content/uploads/2018/01/Screen-Shot-2018-01-30-at-12.29.04-PM.png 650w" sizes="(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px" /></p>
]]></content:encoded>
							<wfw:commentRss>https://courses.ideate.cmu.edu/48-339/s2018/?feed=rss2&#038;p=212</wfw:commentRss>
		<slash:comments>0</slash:comments>
				<enclosure url="https://courses.ideate.cmu.edu/48-339/s2018/wp-content/uploads/2018/01/VID_20180130_115938.mp4" length="12219550" type="video/mp4" />
			</item>
		<item>
		<title>Assignment 2: LED Color Picker</title>
		<link>https://courses.ideate.cmu.edu/48-339/s2018/?p=196</link>
				<comments>https://courses.ideate.cmu.edu/48-339/s2018/?p=196#respond</comments>
				<pubDate>Tue, 30 Jan 2018 04:43:31 +0000</pubDate>
		<dc:creator><![CDATA[vkamath@andrew.cmu.edu]]></dc:creator>
				<category><![CDATA[Assignment 2]]></category>

		<guid isPermaLink="false">https://courses.ideate.cmu.edu/48-339/s2018/?p=196</guid>
				<description><![CDATA[The circuit shown above is a 3 pin led connected to a joystick. It uses the JoyStick movement to change the RGB values and the button press in the joystick is used to switch between states. The system has 5 states All off  Red constant, change G and B by moving the joystick  Green constant, change &#8230; <a href="https://courses.ideate.cmu.edu/48-339/s2018/?p=196" class="more-link">Continue reading<span class="screen-reader-text"> "Assignment 2: LED Color Picker"</span></a>]]></description>
								<content:encoded><![CDATA[<p><img class="alignnone wp-image-198 size-large" src="https://courses.ideate.cmu.edu/48-339/s2018/wp-content/uploads/2018/01/Screen-Shot-2018-01-29-at-11.20.00-PM-1024x460.png" alt="" width="840" height="377" srcset="https://courses.ideate.cmu.edu/48-339/s2018/wp-content/uploads/2018/01/Screen-Shot-2018-01-29-at-11.20.00-PM-1024x460.png 1024w, https://courses.ideate.cmu.edu/48-339/s2018/wp-content/uploads/2018/01/Screen-Shot-2018-01-29-at-11.20.00-PM-300x135.png 300w, https://courses.ideate.cmu.edu/48-339/s2018/wp-content/uploads/2018/01/Screen-Shot-2018-01-29-at-11.20.00-PM-768x345.png 768w, https://courses.ideate.cmu.edu/48-339/s2018/wp-content/uploads/2018/01/Screen-Shot-2018-01-29-at-11.20.00-PM-1200x539.png 1200w" sizes="(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px" /></p>
<p>The circuit shown above is a 3 pin led connected to a joystick. It uses the JoyStick movement to change the RGB values and the button press in the joystick is used to switch between states. The system has 5 states</p>
<ol>
<li>All off</li>
<li> Red constant, change G and B by moving the joystick</li>
<li> Green constant, change R and G by moving the joystick</li>
<li>Blue constant, change others through joystick</li>
<li>All on.</li>
</ol>
<p><iframe width="840" height="630" src="https://www.youtube.com/embed/NRCuPHYUrwQ?feature=oembed" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe></p>
<p>Reflection:  if I were to redo this, I would transfer the states from 2, 3 and 4 making it a real color picker, and I also think the joystick button may not be ideal for an interrupt.</p>
<p><a href="https://courses.ideate.cmu.edu/48-339/s2018/wp-content/uploads/2018/01/A2.zip">Code and Files: A2</a></p>
]]></content:encoded>
							<wfw:commentRss>https://courses.ideate.cmu.edu/48-339/s2018/?feed=rss2&#038;p=196</wfw:commentRss>
		<slash:comments>0</slash:comments>
							</item>
		<item>
		<title>Assignment Two</title>
		<link>https://courses.ideate.cmu.edu/48-339/s2018/?p=204</link>
				<comments>https://courses.ideate.cmu.edu/48-339/s2018/?p=204#respond</comments>
				<pubDate>Tue, 30 Jan 2018 04:30:57 +0000</pubDate>
		<dc:creator><![CDATA[mcherban@andrew.cmu.edu]]></dc:creator>
				<category><![CDATA[Assignment 2]]></category>

		<guid isPermaLink="false">https://courses.ideate.cmu.edu/48-339/s2018/?p=204</guid>
				<description><![CDATA[Hot/Cold I wanted to build upon and improve the previous assignment. The goal is to balance at a certain distance in order to turn on the LED, but done through a classic game of hot or cold. While it&#8217;s rather trivial, it has helped me to better understand the ultrasonic sensor and its possibilities. refining &#8230; <a href="https://courses.ideate.cmu.edu/48-339/s2018/?p=204" class="more-link">Continue reading<span class="screen-reader-text"> "Assignment Two"</span></a>]]></description>
								<content:encoded><![CDATA[<h4>Hot/Cold</h4>
<p>I wanted to build upon and improve the previous assignment. The goal is to balance at a certain distance in order to turn on the LED, but done through a classic game of hot or cold. While it&#8217;s rather trivial, it has helped me to better understand the ultrasonic sensor and its possibilities. refining the sensor data and perfecting the timing is something that I&#8217;d like to explore further down the road.</p>
<p>The states are used in order to guide you through the game. State one lets you now that the game is ready, state two sets a random number for you to find using the ultrasonic sensor, and in state three&#8230;you find the number. Prompted in the serial monitor if you are getting warmer or colder.</p>
<p><img class="alignnone wp-image-206" src="https://courses.ideate.cmu.edu/48-339/s2018/wp-content/uploads/2018/01/hotCold2-300x149.jpg" alt="" width="632" height="314" srcset="https://courses.ideate.cmu.edu/48-339/s2018/wp-content/uploads/2018/01/hotCold2-300x149.jpg 300w, https://courses.ideate.cmu.edu/48-339/s2018/wp-content/uploads/2018/01/hotCold2-768x381.jpg 768w, https://courses.ideate.cmu.edu/48-339/s2018/wp-content/uploads/2018/01/hotCold2-1024x509.jpg 1024w, https://courses.ideate.cmu.edu/48-339/s2018/wp-content/uploads/2018/01/hotCold2-1200x596.jpg 1200w" sizes="(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px" /></p>
<h6>Code:</h6>
<div class="codecolorer-container cpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="cpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #666666;">//--------NEOPIXEL SETUP --------</span><br />
<span style="color: #339900;">#include &amp;lt;Adafruit_NeoPixel.h&amp;gt;</span><br />
<span style="color: #339900;">#ifdef __AVR__</span><br />
<span style="color: #339900;">#include &amp;lt;avr/power.h&amp;gt;</span><br />
<span style="color: #339900;">#endif</span><br />
<span style="color: #0000ff;">static</span> <span style="color: #0000ff;">const</span> <span style="color: #0000ff;">int</span> PIN <span style="color: #000080;">=</span> <span style="color: #0000dd;">40</span><span style="color: #008080;">;</span><br />
<span style="color: #0000ff;">static</span> <span style="color: #0000ff;">const</span> <span style="color: #0000ff;">int</span> NUMPIXELS <span style="color: #000080;">=</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span><br />
Adafruit_NeoPixel pixels <span style="color: #000080;">=</span> Adafruit_NeoPixel<span style="color: #008000;">&#40;</span>NUMPIXELS, PIN, NEO_GRBW <span style="color: #000040;">+</span> NEO_KHZ800<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
<br />
<span style="color: #666666;">//--------ULTRASONIC PINS--------</span><br />
<span style="color: #0000ff;">static</span> <span style="color: #0000ff;">const</span> <span style="color: #0000ff;">int</span> trigPin <span style="color: #000080;">=</span> A0<span style="color: #008080;">;</span><br />
<span style="color: #0000ff;">static</span> <span style="color: #0000ff;">const</span> <span style="color: #0000ff;">int</span> echoPin <span style="color: #000080;">=</span> A1<span style="color: #008080;">;</span><br />
<br />
<span style="color: #666666;">//--------LIGHTS--------</span><br />
<span style="color: #0000ff;">static</span> <span style="color: #0000ff;">const</span> <span style="color: #0000ff;">int</span> ledPin <span style="color: #000080;">=</span> <span style="color: #0000dd;">4</span><span style="color: #008080;">;</span><br />
<br />
<span style="color: #666666;">//--------SWITCH PIN--------</span><br />
<span style="color: #0000ff;">static</span> <span style="color: #0000ff;">const</span> <span style="color: #0000ff;">int</span> switchPin <span style="color: #000080;">=</span> <span style="color: #0000dd;">3</span><span style="color: #008080;">;</span><br />
<br />
<span style="color: #666666;">//------------------------------------------------------------------------------------</span><br />
<br />
<span style="color: #666666;">//--------Global variables--------</span><br />
<br />
<span style="color: #0000ff;">const</span> <span style="color: #0000ff;">bool</span> isInterrupt <span style="color: #000080;">=</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span><br />
<br />
<span style="color: #666666;">// button state</span><br />
<span style="color: #0000ff;">int</span> buttonState <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> <span style="color: #666666;">// current state of the button</span><br />
<br />
<span style="color: #666666;">// Target</span><br />
<span style="color: #0000ff;">int</span> target<span style="color: #008080;">;</span><br />
<br />
<span style="color: #666666;">// Time</span><br />
<span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">long</span> lastSampleTime <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span><br />
<span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">long</span> sampleInterval <span style="color: #000080;">=</span> <span style="color: #0000dd;">5000</span><span style="color: #008080;">;</span> <span style="color: #666666;">// in ms</span><br />
<br />
<span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">long</span> lastSampleTime2 <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span><br />
<span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">long</span> sampleInterval2 <span style="color: #000080;">=</span> <span style="color: #0000dd;">250</span><span style="color: #008080;">;</span> <span style="color: #666666;">// in ms</span><br />
<br />
<span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">long</span> lastSampleTime3 <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span><br />
<span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">long</span> sampleInterval3 <span style="color: #000080;">=</span> <span style="color: #0000dd;">500</span><span style="color: #008080;">;</span> <span style="color: #666666;">// in ms</span><br />
<br />
<span style="color: #666666;">// Ultrasonic</span><br />
<span style="color: #0000ff;">long</span> duration<span style="color: #008080;">;</span><br />
<span style="color: #0000ff;">int</span> distance<span style="color: #008080;">;</span><br />
<br />
<span style="color: #666666;">//------------------------------------------------------------------------------------</span><br />
<br />
<span style="color: #0000ff;">void</span> SwitchPressed<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp;<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>digitalRead<span style="color: #008000;">&#40;</span>switchPin<span style="color: #008000;">&#41;</span> <span style="color: #000080;">==</span> HIGH<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp;<span style="color: #666666;">// this is why people hate C</span><br />
&nbsp;buttonState <span style="color: #000080;">==</span> <span style="color: #0000dd;">3</span> <span style="color: #008080;">?</span> buttonState <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span> <span style="color: #008080;">:</span> buttonState<span style="color: #000040;">++</span><span style="color: #008080;">;</span><br />
&nbsp;<span style="color: #008000;">&#125;</span><br />
&nbsp;<span style="color: #666666;">// Serial.println(buttonState);</span><br />
<span style="color: #008000;">&#125;</span><br />
<br />
<span style="color: #666666;">//------------------------------------------------------------------------------------</span><br />
<br />
<span style="color: #0000ff;">void</span> setup<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
<br />
Serial.<span style="color: #007788;">begin</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">9600</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
<br />
pinMode<span style="color: #008000;">&#40;</span>ledPin, OUTPUT<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;pinMode<span style="color: #008000;">&#40;</span>switchPin, INPUT<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;pinMode<span style="color: #008000;">&#40;</span>trigPin, OUTPUT<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;pinMode<span style="color: #008000;">&#40;</span>echoPin, INPUT<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
<br />
<span style="color: #666666;">// attach the interrupt pin to a method</span><br />
&nbsp;<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>isInterrupt<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp;attachInterrupt <span style="color: #008000;">&#40;</span>digitalPinToInterrupt <span style="color: #008000;">&#40;</span>switchPin<span style="color: #008000;">&#41;</span>, SwitchPressed, CHANGE<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;<span style="color: #008000;">&#125;</span><br />
&nbsp;randomSeed<span style="color: #008000;">&#40;</span>analogRead<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">2</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;pixels.<span style="color: #007788;">begin</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// This initializes the NeoPixel library.</span><br />
<span style="color: #008000;">&#125;</span><br />
<br />
<span style="color: #0000ff;">void</span> loop<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp;<span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">long</span> now <span style="color: #000080;">=</span> millis<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
<br />
<span style="color: #0000ff;">switch</span> <span style="color: #008000;">&#40;</span>buttonState<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp;<span style="color: #0000ff;">case</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">:</span><br />
&nbsp;pixelBlinkGreen<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;Serial.<span style="color: #007788;">println</span> <span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;Ready To Start Game&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;<span style="color: #0000ff;">break</span><span style="color: #008080;">;</span><br />
&nbsp;<span style="color: #0000ff;">case</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">:</span><br />
&nbsp;<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>lastSampleTime <span style="color: #000040;">+</span> sampleInterval <span style="color: #000040;">&amp;</span>lt<span style="color: #008080;">;</span> now<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp;lastSampleTime <span style="color: #000080;">=</span> now<span style="color: #008080;">;</span><br />
&nbsp;target <span style="color: #000080;">=</span> random<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">1</span>, <span style="color: #0000dd;">150</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;Serial.<span style="color: #007788;">print</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;Target Set&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;<span style="color: #008000;">&#125;</span><br />
&nbsp;pixels.<span style="color: #007788;">setPixelColor</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">0</span>, pixels.<span style="color: #007788;">Color</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">0</span>, <span style="color: #0000dd;">255</span>, <span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;<span style="color: #0000ff;">break</span><span style="color: #008080;">;</span><br />
&nbsp;<span style="color: #0000ff;">case</span> <span style="color: #0000dd;">2</span><span style="color: #008080;">:</span><br />
&nbsp;pixels.<span style="color: #007788;">setPixelColor</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">0</span>, pixels.<span style="color: #007788;">Color</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">255</span>, <span style="color: #0000dd;">200</span>, <span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;<span style="color: #666666;">// Serial.print(&quot;Find &quot;);</span><br />
&nbsp;<span style="color: #666666;">// Serial.println(target);</span><br />
&nbsp;hotCold<span style="color: #008000;">&#40;</span>target<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;<span style="color: #0000ff;">break</span><span style="color: #008080;">;</span><br />
&nbsp;<span style="color: #0000ff;">default</span><span style="color: #008080;">:</span><br />
&nbsp;pixelBlinkYellow<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;Serial.<span style="color: #007788;">println</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;Push Button For New Game&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;<span style="color: #666666;">// statements</span><br />
&nbsp;<span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span><br />
<span style="color: #ff0000; font-style: italic;">/*<br />
&nbsp;if (buttonState == 0) {<br />
&nbsp;pixelBlinkGreen();<br />
&nbsp;Serial.println (&quot;GREEN BLINK&quot;);<br />
&nbsp;}<br />
&nbsp;else if (buttonState == 1) {<br />
&nbsp;if (lastSampleTime + sampleInterval &amp;lt; now) {<br />
&nbsp;lastSampleTime = now;<br />
&nbsp;target = random(1, 150);<br />
&nbsp;Serial.print(&quot;Target = &quot;);<br />
&nbsp;Serial.println(target);<br />
&nbsp;}<br />
&nbsp;pixelBlinkYellow();<br />
&nbsp;}<br />
&nbsp;else if (buttonState == 2) {<br />
&nbsp;pixels.setPixelColor(0, pixels.Color(255, 200, 0));<br />
&nbsp;// Serial.print(&quot;Find &quot;);<br />
&nbsp;// Serial.println(target);<br />
&nbsp;hotCold(target);<br />
&nbsp;}<br />
&nbsp;}<br />
*/</span><br />
<br />
<span style="color: #666666;">//------------------------------------------------------------------------------------</span><br />
<br />
<span style="color: #0000ff;">void</span> hotCold<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> x<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp;digitalWrite<span style="color: #008000;">&#40;</span>trigPin, LOW<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;delayMicroseconds<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">2</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;digitalWrite<span style="color: #008000;">&#40;</span>trigPin, HIGH<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;delayMicroseconds<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">10</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;digitalWrite<span style="color: #008000;">&#40;</span>trigPin, LOW<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
<br />
duration <span style="color: #000080;">=</span> pulseIn<span style="color: #008000;">&#40;</span>echoPin, HIGH<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;distance <span style="color: #000080;">=</span> duration <span style="color: #000040;">/</span> <span style="color: #0000dd;">10</span> <span style="color: #000040;">/</span> <span style="color: #0000dd;">2</span> <span style="color: #008080;">;</span><br />
<br />
<span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">long</span> now2 <span style="color: #000080;">=</span> millis<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>lastSampleTime2 <span style="color: #000040;">+</span> sampleInterval2 <span style="color: #000040;">&amp;</span>lt<span style="color: #008080;">;</span> now2<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp;lastSampleTime2 <span style="color: #000080;">=</span> now2<span style="color: #008080;">;</span><br />
&nbsp;<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>distance <span style="color: #000040;">&amp;</span>lt<span style="color: #008080;">;</span><span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>target <span style="color: #000040;">+</span> <span style="color: #0000dd;">5</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span><span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span> <span style="color: #008000;">&#40;</span>distance <span style="color: #000040;">&amp;</span>gt<span style="color: #008080;">;</span><span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>target <span style="color: #000040;">-</span> <span style="color: #0000dd;">5</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp;Serial.<span style="color: #007788;">println</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;ON FIRE!&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;ledOn<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;pixelBlinkPink<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;<span style="color: #008000;">&#125;</span> <span style="color: #0000ff;">else</span> <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>distance <span style="color: #000040;">&amp;</span>lt<span style="color: #008080;">;</span><span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>target <span style="color: #000040;">+</span> <span style="color: #0000dd;">10</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span><span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span> <span style="color: #008000;">&#40;</span>distance <span style="color: #000040;">&amp;</span>gt<span style="color: #008080;">;</span><span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>target <span style="color: #000040;">-</span> <span style="color: #0000dd;">10</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp;Serial.<span style="color: #007788;">println</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;Things are heating up&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;ledOff<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;<span style="color: #008000;">&#125;</span> <span style="color: #0000ff;">else</span> <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>distance <span style="color: #000040;">&amp;</span>lt<span style="color: #008080;">;</span><span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>target <span style="color: #000040;">+</span> <span style="color: #0000dd;">20</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span><span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span> <span style="color: #008000;">&#40;</span>distance <span style="color: #000040;">&amp;</span>gt<span style="color: #008080;">;</span><span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>target <span style="color: #000040;">-</span> <span style="color: #0000dd;">20</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp;Serial.<span style="color: #007788;">println</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;Warmer...&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;ledOff<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;<span style="color: #008000;">&#125;</span> <span style="color: #0000ff;">else</span> <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>distance <span style="color: #000040;">&amp;</span>lt<span style="color: #008080;">;</span><span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>target <span style="color: #000040;">+</span> <span style="color: #0000dd;">30</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span><span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span> <span style="color: #008000;">&#40;</span>distance <span style="color: #000040;">&amp;</span>gt<span style="color: #008080;">;</span><span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>target <span style="color: #000040;">-</span> <span style="color: #0000dd;">30</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp;Serial.<span style="color: #007788;">println</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;Cooler...&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;ledOff<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;<span style="color: #008000;">&#125;</span> <span style="color: #0000ff;">else</span> <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>distance <span style="color: #000040;">&amp;</span>lt<span style="color: #008080;">;</span><span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>target <span style="color: #000040;">+</span> <span style="color: #0000dd;">40</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span><span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span> <span style="color: #008000;">&#40;</span>distance <span style="color: #000040;">&amp;</span>gt<span style="color: #008080;">;</span><span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>target <span style="color: #000040;">-</span> <span style="color: #0000dd;">40</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp;Serial.<span style="color: #007788;">println</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;Pretty Cold&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;ledOff<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;<span style="color: #008000;">&#125;</span> <span style="color: #0000ff;">else</span> <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>distance <span style="color: #000040;">&amp;</span>lt<span style="color: #008080;">;</span><span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>target <span style="color: #000040;">+</span> <span style="color: #0000dd;">50</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span><span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span> <span style="color: #008000;">&#40;</span>distance <span style="color: #000040;">&amp;</span>gt<span style="color: #008080;">;</span><span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>target <span style="color: #000040;">-</span> <span style="color: #0000dd;">50</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp;Serial.<span style="color: #007788;">println</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;Ice Cold, Elsa&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;ledOff<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;<span style="color: #008000;">&#125;</span> <span style="color: #0000ff;">else</span> <span style="color: #008000;">&#123;</span><br />
&nbsp;ledOff<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;<span style="color: #666666;">//Serial.println(&quot;Something is wrong&quot;);</span><br />
&nbsp;<span style="color: #008000;">&#125;</span><br />
&nbsp;<span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span><br />
<br />
<span style="color: #0000ff;">void</span> pixelBlinkGreen<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp;pixels.<span style="color: #007788;">setPixelColor</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">0</span>, pixels.<span style="color: #007788;">Color</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">0</span>, <span style="color: #0000dd;">255</span>, <span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;pixels.<span style="color: #007788;">show</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// This sends the updated pixel color to the hardware.</span><br />
&nbsp;delay<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">500</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;pixels.<span style="color: #007788;">setPixelColor</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">0</span>, pixels.<span style="color: #007788;">Color</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">0</span>, <span style="color: #0000dd;">0</span>, <span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;pixels.<span style="color: #007788;">show</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// This sends the updated pixel color to the hardware.</span><br />
&nbsp;delay<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">500</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<br />
<span style="color: #0000ff;">void</span> pixelBlinkYellow<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp;pixels.<span style="color: #007788;">setPixelColor</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">0</span>, pixels.<span style="color: #007788;">Color</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">255</span>, <span style="color: #0000dd;">200</span>, <span style="color: #0000dd;">0</span>, <span style="color: #0000dd;">75</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;pixels.<span style="color: #007788;">show</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// This sends the updated pixel color to the hardware.</span><br />
&nbsp;delay<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">250</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;pixels.<span style="color: #007788;">setPixelColor</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">0</span>, pixels.<span style="color: #007788;">Color</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">0</span>, <span style="color: #0000dd;">0</span>, <span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;pixels.<span style="color: #007788;">show</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// This sends the updated pixel color to the hardware.</span><br />
&nbsp;delay<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">250</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<br />
<span style="color: #0000ff;">void</span> pixelBlinkWhite<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp;pixels.<span style="color: #007788;">setPixelColor</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">0</span>, pixels.<span style="color: #007788;">Color</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">255</span>, <span style="color: #0000dd;">255</span>, <span style="color: #0000dd;">255</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;pixels.<span style="color: #007788;">show</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// This sends the updated pixel color to the hardware.</span><br />
&nbsp;delay<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">300</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;pixels.<span style="color: #007788;">setPixelColor</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">0</span>, pixels.<span style="color: #007788;">Color</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">0</span>, <span style="color: #0000dd;">0</span>, <span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;pixels.<span style="color: #007788;">show</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// This sends the updated pixel color to the hardware.</span><br />
&nbsp;delay<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">250</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<br />
<span style="color: #0000ff;">void</span> pixelBlinkPink<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp;pixels.<span style="color: #007788;">setPixelColor</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">0</span>, pixels.<span style="color: #007788;">Color</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">254</span>, <span style="color: #0000dd;">6</span>, <span style="color: #0000dd;">141</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;pixels.<span style="color: #007788;">show</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// This sends the updated pixel color to the hardware.</span><br />
&nbsp;delay<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">300</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;pixels.<span style="color: #007788;">setPixelColor</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">0</span>, pixels.<span style="color: #007788;">Color</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">0</span>, <span style="color: #0000dd;">0</span>, <span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;pixels.<span style="color: #007788;">show</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// This sends the updated pixel color to the hardware.</span><br />
&nbsp;delay<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">250</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<br />
<span style="color: #0000ff;">void</span> pixelOff<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp;pixels.<span style="color: #007788;">setPixelColor</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">0</span>, pixels.<span style="color: #007788;">Color</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">0</span>, <span style="color: #0000dd;">0</span>, <span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp;pixels.<span style="color: #007788;">show</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// This sends the updated pixel color to the hardware.</span><br />
<span style="color: #008000;">&#125;</span><br />
<br />
<span style="color: #0000ff;">void</span> ledOn<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp;digitalWrite<span style="color: #008000;">&#40;</span>ledPin, HIGH<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<br />
<span style="color: #0000ff;">void</span> ledOff<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp;digitalWrite<span style="color: #008000;">&#40;</span>ledPin, LOW<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<h6>Files:</h6>
<p><a href="https://courses.ideate.cmu.edu/48-339/s2018/wp-content/uploads/2018/02/Cherban_assignment02.zip">Fritzing &amp; Arduino Files</a></p>
]]></content:encoded>
							<wfw:commentRss>https://courses.ideate.cmu.edu/48-339/s2018/?feed=rss2&#038;p=204</wfw:commentRss>
		<slash:comments>0</slash:comments>
							</item>
		<item>
		<title>Assignment 2</title>
		<link>https://courses.ideate.cmu.edu/48-339/s2018/?p=193</link>
				<comments>https://courses.ideate.cmu.edu/48-339/s2018/?p=193#respond</comments>
				<pubDate>Tue, 30 Jan 2018 04:13:49 +0000</pubDate>
		<dc:creator><![CDATA[Rachel Wong]]></dc:creator>
				<category><![CDATA[Assignment 2]]></category>

		<guid isPermaLink="false">https://courses.ideate.cmu.edu/48-339/s2018/?p=193</guid>
				<description><![CDATA[Goal: The goal for my state machine was to build a basic alert system that tells you when there is someone/something in the proximity. The switch is the state change that turns the entire alert system on or off. This is essential for the edge case when you are expecting many people and do not &#8230; <a href="https://courses.ideate.cmu.edu/48-339/s2018/?p=193" class="more-link">Continue reading<span class="screen-reader-text"> "Assignment 2"</span></a>]]></description>
								<content:encoded><![CDATA[<p>Goal: The goal for my state machine was to build a basic alert system that tells you when there is someone/something in the proximity. The switch is the state change that turns the entire alert system on or off. This is essential for the edge case when you are expecting many people and do not need to be alerted. There were three LED colors: yellow for idle (nothing in the proximity), red for something physically there and it is light out, and green for something physically there and it is dark out.</p>
<p>Reflection: If I were to update/re-do this, I would change the code so the interrupt is the proximity sensor rather than the switch. I would also change the light so the green represents light and proximity and red represents dark and proximity. This would align with my overarching ideal goal to make a front door security system. I would also change the light/dark reading to a boolean.</p>
<p><iframe width="840" height="630" src="https://www.youtube.com/embed/2i0dLhgass4?feature=oembed" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe></p>
<p>(My unstable hand is to blame for the flickering green light)</p>
<p><img class="alignnone wp-image-194" src="https://courses.ideate.cmu.edu/48-339/s2018/wp-content/uploads/2018/01/assignment2-300x272.png" alt="" width="532" height="482" srcset="https://courses.ideate.cmu.edu/48-339/s2018/wp-content/uploads/2018/01/assignment2-300x272.png 300w, https://courses.ideate.cmu.edu/48-339/s2018/wp-content/uploads/2018/01/assignment2-768x697.png 768w, https://courses.ideate.cmu.edu/48-339/s2018/wp-content/uploads/2018/01/assignment2-1024x929.png 1024w, https://courses.ideate.cmu.edu/48-339/s2018/wp-content/uploads/2018/01/assignment2-1200x1089.png 1200w" sizes="(max-width: 532px) 85vw, 532px" /></p>
<pre>

<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">&nbsp;// Define constant values.<br />
<br />
// The wiring assignment.<br />
#include<br />
<br />
static const int SWITCH_PIN = 3;<br />
static const int LED1Pin = 4;<br />
static const int LED2Pin = 5;<br />
static const int LED3Pin = 13;<br />
static const int lightSensor = A0;<br />
bool LEDState = false;<br />
static const int sampleSize = 16;<br />
unsigned int readings[sampleSize];<br />
unsigned int sampleIndex = 0;<br />
static const int nighttime = 50;<br />
const int TRIG_PIN = 9;<br />
const int ECHO_PIN = 8;<br />
const int MAX_DISTANCE = 700;<br />
<br />
NewPing sonar(TRIG_PIN, ECHO_PIN, MAX_DISTANCE);<br />
<br />
void SwitchPressed()<br />
{<br />
if (digitalRead(SWITCH_PIN) == 1) {<br />
LEDState = true;<br />
}<br />
else{<br />
LEDState = false;<br />
}<br />
}<br />
<br />
// ================================================================================<br />
// Configure the hardware once after booting up. This runs once after pressing<br />
// reset or powering up the board.<br />
<br />
void setup()<br />
{<br />
// Initialize the serial UART at 9600 bits per second.<br />
<br />
Serial.begin(115200);<br />
<br />
pinMode(LED_BUILTIN, OUTPUT);<br />
<br />
pinMode(SWITCH_PIN, INPUT);<br />
<br />
pinMode(LED1Pin, OUTPUT);<br />
<br />
pinMode(LED2Pin, OUTPUT);<br />
<br />
pinMode(LED3Pin, OUTPUT);<br />
<br />
pinMode(lightSensor, INPUT);<br />
<br />
pinMode(TRIG_PIN, OUTPUT);<br />
<br />
digitalWrite(TRIG_PIN, LOW);<br />
<br />
// Initialize the echo pin for input.<br />
pinMode(ECHO_PIN, INPUT);<br />
<br />
attachInterrupt (digitalPinToInterrupt (SWITCH_PIN), SwitchPressed, CHANGE);<br />
<br />
}<br />
<br />
// ================================================================================<br />
// Run one iteration of the main event loop. The Arduino system will call this<br />
// function over and over forever.<br />
<br />
void loop()<br />
{<br />
<br />
int photo = analogRead(lightSensor);<br />
<br />
readings[sampleIndex] = photo;<br />
<br />
if (sampleIndex &amp;lt; (sampleSize -1)) {<br />
sampleIndex++;<br />
}<br />
else {<br />
sampleIndex = 0;<br />
}<br />
<br />
int median = 0;<br />
int low = 1024;<br />
int high = 0;<br />
int mean = 0;<br />
for (int i = 0; i &amp;lt; sampleSize; i++) {<br />
mean += readings[i];<br />
if (readings[i] &amp;lt; low) { low = readings[i]; } if (readings[i] &amp;gt; high) {<br />
high = readings[i];<br />
}<br />
}<br />
mean = mean / sampleSize;<br />
bubbleSort();<br />
median = readings[sampleSize / 2];<br />
<br />
//TURNED ON, IDLE STATE<br />
<br />
if (LEDState &amp;amp;&amp;amp; sonar.ping_median() &amp;lt; 700 &amp;amp;&amp;amp; mean &amp;gt; nighttime ) {<br />
digitalWrite(LED1Pin, 255);<br />
digitalWrite(LED2Pin, 0);<br />
digitalWrite(LED3Pin, 0);<br />
}<br />
<br />
else if (LEDState &amp;amp;&amp;amp; sonar.ping_median() &amp;lt; 700 &amp;amp;&amp;amp; mean &amp;lt; nighttime ) {<br />
digitalWrite(LED1Pin, 0);<br />
digitalWrite(LED2Pin, 0);<br />
digitalWrite(LED3Pin, 255);<br />
}<br />
<br />
//TURNED OFF<br />
<br />
else if (!LEDState) {<br />
digitalWrite(LED2Pin, 0);<br />
digitalWrite(LED3Pin, 0);<br />
digitalWrite(LED1Pin, 0);<br />
}<br />
<br />
else {<br />
digitalWrite(LED2Pin, 255);<br />
digitalWrite(LED3Pin, 0);<br />
digitalWrite(LED1Pin, 0);<br />
}<br />
<br />
delay(500);<br />
Serial.println(&quot;mean:&quot;);<br />
Serial.println(mean);<br />
Serial.println(&quot;median:&quot;);<br />
Serial.println(sonar.ping_median());<br />
}<br />
<br />
// tigoe's sort for an array<br />
void bubbleSort() {<br />
int out, in, swapper;<br />
for(out=0 ; out &amp;lt; sampleSize; out++) { // outer loop<br />
for(in=out; in&amp;lt;(sampleSize-1); in++) { // inner loop if( readings[in] &amp;gt; readings[in+1] ) { // out of order?<br />
// swap them:<br />
swapper = readings[in];<br />
readings [in] = readings[in+1];<br />
readings[in+1] = swapper;<br />
}<br />
}<br />
}<br />
}</div></div>

</pre>
<p>&nbsp;</p>
]]></content:encoded>
							<wfw:commentRss>https://courses.ideate.cmu.edu/48-339/s2018/?feed=rss2&#038;p=193</wfw:commentRss>
		<slash:comments>0</slash:comments>
							</item>
		<item>
		<title>Assignment2 &#8211; Knock Interface</title>
		<link>https://courses.ideate.cmu.edu/48-339/s2018/?p=184</link>
				<comments>https://courses.ideate.cmu.edu/48-339/s2018/?p=184#respond</comments>
				<pubDate>Mon, 29 Jan 2018 23:16:49 +0000</pubDate>
		<dc:creator><![CDATA[ditoh@andrew.cmu.edu]]></dc:creator>
				<category><![CDATA[Assignment 2]]></category>

		<guid isPermaLink="false">https://courses.ideate.cmu.edu/48-339/s2018/?p=184</guid>
				<description><![CDATA[Imagine your desks, doors, and floors turning into an interface that responds to knocks. What if you could control room lighting with the silent knocks? What if you could customize the knock interaction for each object? In this assignment, I built an interactive system that is able to detect and record knock patterns. Used a piezo sensor &#8230; <a href="https://courses.ideate.cmu.edu/48-339/s2018/?p=184" class="more-link">Continue reading<span class="screen-reader-text"> "Assignment2 &#8211; Knock Interface"</span></a>]]></description>
								<content:encoded><![CDATA[<p>Imagine your desks, doors, and floors turning into an interface that responds to knocks. What if you could control room lighting with the silent knocks? What if you could customize the knock interaction for each object? In this assignment, I built an interactive system that is able to detect and record knock patterns. Used a piezo sensor to detect the knock vibrations and a button to trigger interrupt to switch 2 different modes &#8211; detect and record. Knock detection result is displayed on a console.</p>
<p>The system consists of 6 states in total &#8211; wait / read / output for detect mode and wait / read / record for record mode.</p>
<p><img class="alignnone size-full wp-image-187" src="https://courses.ideate.cmu.edu/48-339/s2018/wp-content/uploads/2018/01/StateDiagram-Assign2.png" alt="" width="644" height="423" srcset="https://courses.ideate.cmu.edu/48-339/s2018/wp-content/uploads/2018/01/StateDiagram-Assign2.png 644w, https://courses.ideate.cmu.edu/48-339/s2018/wp-content/uploads/2018/01/StateDiagram-Assign2-300x197.png 300w" sizes="(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px" /></p>
<p>Demo:</p>
<p><iframe width="840" height="630" src="https://www.youtube.com/embed/Hyqsa6e8Ss0?feature=oembed" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe></p>
<p><a href="https://courses.ideate.cmu.edu/48-339/s2018/wp-content/uploads/2018/01/Assign2-ditoh.zip">Code and fritzing here</a></p>
]]></content:encoded>
							<wfw:commentRss>https://courses.ideate.cmu.edu/48-339/s2018/?feed=rss2&#038;p=184</wfw:commentRss>
		<slash:comments>0</slash:comments>
							</item>
		<item>
		<title>Assignment 2: State Machines and Interrupts</title>
		<link>https://courses.ideate.cmu.edu/48-339/s2018/?p=176</link>
				<comments>https://courses.ideate.cmu.edu/48-339/s2018/?p=176#respond</comments>
				<pubDate>Thu, 25 Jan 2018 23:39:59 +0000</pubDate>
		<dc:creator><![CDATA[jet Townsend]]></dc:creator>
				<category><![CDATA[Assignment 2]]></category>

		<guid isPermaLink="false">https://courses.ideate.cmu.edu/48-339/s2018/?p=176</guid>
				<description><![CDATA[Assignment 2: State Machines and Interrupts Due 23:59, 29 January 2018.  We will discuss in class on the 30th and suggest improvements or analyze different ways to resolve your problem. Requirements State a question or process you would like to solve. (Ex: &#8220;control the lights in a room based on a door being opened and &#8230; <a href="https://courses.ideate.cmu.edu/48-339/s2018/?p=176" class="more-link">Continue reading<span class="screen-reader-text"> "Assignment 2: State Machines and Interrupts"</span></a>]]></description>
								<content:encoded><![CDATA[<h2>Assignment 2: State Machines and Interrupts</h2>
<p>Due 23:59, 29 January 2018.  We will discuss in class on the 30th and suggest improvements or analyze different ways to resolve your problem.</p>
<h2>Requirements</h2>
<p>State a question or process you would like to solve. (Ex: &#8220;control the lights in a room based on a door being opened and curtains being opened or closed.&#8221;)  Create a physical interaction using a state machine driven by inputs and interrupts that collects data, interprets the data, then displays a result via console, LEDs, or other output devices. Speakers are acceptable but must be executed in a useful manner, kinematic solutions are also welcome.</p>
<p>The state machine should have at least three states not including on and off states.  Declare whether your states have an order or if any state can transition to another state.</p>
<p>Post a short video showing the various states, I suggest vimeo or youtube.   For your Arduino and Fritzing sketches, make a zip file or gzip/tar bundled and post that to the blog.</p>
]]></content:encoded>
							<wfw:commentRss>https://courses.ideate.cmu.edu/48-339/s2018/?feed=rss2&#038;p=176</wfw:commentRss>
		<slash:comments>0</slash:comments>
							</item>
	</channel>
</rss>
