<?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>eclecticc &#187; laser</title>
	<atom:link href="http://eclecti.cc/tag/laser/feed" rel="self" type="application/rss+xml" />
	<link>http://eclecti.cc</link>
	<description></description>
	<lastBuildDate>Tue, 20 Dec 2011 07:16:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Sleep Remaining Indicator: A Laser Alarm Clock</title>
		<link>http://eclecti.cc/hardware/sleep-remaining-indicator-a-laser-alarm-clock</link>
		<comments>http://eclecti.cc/hardware/sleep-remaining-indicator-a-laser-alarm-clock#comments</comments>
		<pubDate>Wed, 20 Jan 2010 08:15:19 +0000</pubDate>
		<dc:creator>nrp</dc:creator>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[arduino]]></category>
		<category><![CDATA[chumby]]></category>
		<category><![CDATA[laser]]></category>
		<category><![CDATA[servo]]></category>

		<guid isPermaLink="false">http://eclecti.cc/?p=399</guid>
		<description><![CDATA[The chunk of title after the colon intends to serve as an explanation of what a sleep remaining indicator is. However, this project is neither an alarm nor a clock. It is a visual indicator of approximately how much time I have remaining to sleep in the night. This may not be a problem you [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://eclecti.cc/files/2010/01/sleepremainingindicator.jpg"><img class="alignnone size-large wp-image-401" title="The original plan was to use an ATTiny85, but I ran out of resonators." src="http://eclecti.cc/files/2010/01/sleepremainingindicator-700x525.jpg" alt="Sleep remaining indicator" width="700" height="525" /></a></p>
<p>The chunk of title after the colon intends to serve as an explanation of what a sleep remaining indicator is.  However, this project is neither an alarm nor a clock.  It is a visual <em>indicator</em> of approximately how much time I have <em>remaining</em> to <em>sleep</em> in the night.</p>
<p>This may not be a problem you need solved.  If, however, like me you wear glasses or contacts, the world when you are in bed turns into a blurry mess.  Normally I reach over and unlock my phone or lean over and squint at my <a href="http://www.chumby.com/">Chumby One</a>, but those actions make it harder to get back to sleep.  What I wanted was a way to instantly know how much longer I could sleep before my alarm would go off.</p>
<p>My solution involves a line laser, a servo, and an Arduino.  I set a potentiometer with a number dial to approximately the right length of time in hours and hit the reset button.  The servo with the line laser attached will shine the laser line onto the ceiling.  The servo will then slowly rotate, moving the laser line underneath a cover made of Lego pieces, making the length of line showing on the ceiling shrink over the hours.  It&#8217;s a little like an hourglass, but with lasers.</p>
<p><a href="http://eclecti.cc/files/2010/01/laserline.jpg"><img class="alignnone size-large wp-image-400" title="It's being powered off the Chumby for convenience." src="http://eclecti.cc/files/2010/01/laserline-700x525.jpg" alt="Laser line" width="700" height="525" /></a></p>
<p>Here&#8217;s the Arduino sketch.  Use it under whatever license you want.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* Sleep Remaining Indicator v1.0
 * by Nirav Patel &lt;http://eclecti.cc&gt;
 */</span>
&nbsp;
<span style="color: #339933;">#include &lt;Servo.h&gt;</span>
<span style="color: #339933;">#include &lt;math.h&gt;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//#define photoPin 1</span>
<span style="color: #666666; font-style: italic;">//#define laserPin 9</span>
<span style="color: #339933;">#define potPin 0</span>
<span style="color: #339933;">#define servoPin 10</span>
<span style="color: #339933;">#define M_PI_4 (M_PI/4.0)</span>
<span style="color: #339933;">#define MINSERVO 1190 // The laser line is no longer visible</span>
<span style="color: #339933;">#define MAXSERVO 1810 // The laser line is at its longest</span>
&nbsp;
<span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> startTime<span style="color: #339933;">;</span>
<span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> totalTime<span style="color: #339933;">;</span>
<span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> lastVal<span style="color: #339933;">;</span>
Servo laserServo<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  Serial.<span style="color: #202020;">begin</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">9600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//  pinMode(photoPin, INPUT);</span>
  pinMode<span style="color: #009900;">&#40;</span>potPin<span style="color: #339933;">,</span> INPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// this magic converts the pot value to 0 to 9 hours in milliseconds.</span>
  totalTime <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span><span style="color: #009900;">&#41;</span><span style="color: #0000dd;">31641</span><span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1024</span><span style="color: #339933;">-</span>analogRead<span style="color: #009900;">&#40;</span>potPin<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'Time in hours: '</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">double</span><span style="color: #009900;">&#41;</span>totalTime<span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">double</span><span style="color: #009900;">&#41;</span><span style="color:#800080;">3600000.0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  laserServo.<span style="color: #202020;">attach</span><span style="color: #009900;">&#40;</span>servoPin<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  startTime <span style="color: #339933;">=</span> millis<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  lastVal <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> loop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// The laser brightness should depend on the ambient light in the room.</span>
  <span style="color: #666666; font-style: italic;">// Unfortunately, my laser dislikes PWM, so I just have it hooked to 3.3v</span>
<span style="color: #666666; font-style: italic;">//  unsigned int light = analogRead(photoPin);</span>
<span style="color: #666666; font-style: italic;">//  analogWrite(laserPin,light&gt;&gt;2);</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// calculate the time we've been running (well, sleeping)</span>
  <span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> time <span style="color: #339933;">=</span> millis<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span>startTime<span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// Note that one could use this as an alarm clock by setting off a buzzer or</span>
  <span style="color: #666666; font-style: italic;">// even having the servo rotate loudly</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>time <span style="color: #339933;">&gt;</span> totalTime<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    laserServo.<span style="color: #202020;">writeMicroseconds</span><span style="color: #009900;">&#40;</span>MINSERVO<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// This trig makes the line length shrink uniformly over time.</span>
  time <span style="color: #339933;">=</span> totalTime<span style="color: #339933;">-</span>time<span style="color: #339933;">;</span>
  <span style="color: #993333;">double</span> angle <span style="color: #339933;">=</span> atan2<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">double</span><span style="color: #009900;">&#41;</span>time<span style="color: #339933;">,</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">double</span><span style="color: #009900;">&#41;</span>totalTime<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> servoVal <span style="color: #339933;">=</span>  <span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>angle<span style="color: #339933;">/</span>M_PI_4<span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">double</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>MAXSERVO<span style="color: #339933;">-</span>MINSERVO<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span>MINSERVO<span style="color: #339933;">;</span>
&nbsp;
  servoVal <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>servoVal <span style="color: #339933;">&gt;</span> MAXSERVO<span style="color: #339933;">?</span> MAXSERVO <span style="color: #339933;">:</span> <span style="color: #009900;">&#40;</span>servoVal <span style="color: #339933;">&lt;</span> MINSERVO <span style="color: #339933;">?</span> MINSERVO <span style="color: #339933;">:</span> servoVal<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// The servo is imperfect, so don't move unless the value actually changed</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>servoVal <span style="color: #339933;">!=</span> lastVal<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span>servoVal<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    laserServo.<span style="color: #202020;">writeMicroseconds</span><span style="color: #009900;">&#40;</span>servoVal<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    lastVal <span style="color: #339933;">=</span> servoVal<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// tick like a clock</span>
  delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://eclecti.cc/hardware/sleep-remaining-indicator-a-laser-alarm-clock/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.248 seconds -->

