All posts by johncohn

Thrusday night – open source / open sores

Got home so late last night after that long but productive trip to NY.. I paid for it today.. I am home with a virus of some sort.. I’m fevery and achy… and I have open sores on my tongue… yuck !  ..
   It dodn’t slow me down though. I had a very productive day just working from home. I’m spending lots of time on the phone talking to new folks abotu soem ideas I have.. it’s fun meeting these new folks. Speaking of new folks and open sores…  A chance meeting aI had at makerfaire has turned out to be pretty productive. I was wearign the  LED color changing halo that I often wear at events… I ran into a guy , Xander H. at one of the booths who recognized the chips that I was using in my halo.. and asked me how I’d figured them out. . Readers of this blog may recall that I struggled mightely to figure out the inner workigns of those chips back before christmas as I was maign headbands for both boys.    Anyway.. Xander had been struggling with the same horrible chineese documentation that I’d had to work through.. We exchenged busness cards.. then email.. and finally source doe.. and the result is a cool new opensource librbary Xander wrote for driving these strips. I love that this chance meeting at th Faire led to a contribution to geek culture..   It really is world 2.0

.r{}* LEDStrip – Arduino driver for HL1606-based LED strips

 * Thanks to: John M Cohn
 * Copyright (c) 2009, Synoptic Labs
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *   * Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *   * Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in the
 *     documentation and/or other materials provided with the distribution.
 *   * Neither the name of the .. nor the
 *     names of its contributors may be used to endorse or promote products
 *     derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY SYNOPTIC LABS ”AS IS” AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL SYNOPTIC LABS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include “WConstants.h”
#include “LEDStrip.h”
LEDStrip::LEDStrip(int dPin, int sPin, int latchPin, int clkPin)
{
  _dPin = dPin;
  _sPin = sPin;
  _latchPin = latchPin;
  _clkPin = clkPin;
  _faderEnabled = 0;
 
  digitalWrite(_dPin, LOW);
  pinMode(_dPin, OUTPUT);
  digitalWrite(_sPin, LOW);
  pinMode(_sPin, OUTPUT);
  digitalWrite(_latchPin, LOW);
  pinMode(_latchPin, OUTPUT);
  digitalWrite(_clkPin, LOW);
  pinMode(_clkPin, OUTPUT);
}
void LEDStrip::faderCrank()
{
  unsigned long mymillis;
 
  if (!_faderEnabled) return;
  mymillis = millis();
  // Give us 250ms slop in case we don’t exactly catch our edge.
  if (mymillis >= _faderPulseNextEdge && mymillis < _faderPulseNextEdge + 250) {
    if (digitalRead(_sPin) == HIGH) {
      digitalWrite(_sPin, LOW);
    } else {
      // only load new value of _faderPulseHalfWidth on rising edge
      digitalWrite(_sPin, HIGH);
      _faderPulseHalfWidth = _faderPulseNewHalfWidth;
    }
    _faderPulseNextEdge = mymillis + _faderPulseHalfWidth;
  }
}
unsigned int LEDStrip::faderSpeedGet()
{
  return _faderPulseHalfWidth;
}
void LEDStrip::faderSpeedSet(unsigned int halfWidthms)
{
  if (halfWidthms == 0) {
    _faderEnabled = 0;
    _faderPulseHalfWidth = 0;
    _faderPulseNewHalfWidth = 0;
    digitalWrite(_sPin, LOW);
    return;  
  }
  _faderPulseNewHalfWidth = halfWidthms;
 
  // if we’re already running, don’t re-init _faderPulseNextEdge
  if (_faderEnabled != 1) {  // starting from non-running state,
    _faderEnabled = 1;
    digitalWrite(_sPin, HIGH);
    _faderPulseHalfWidth = halfWidthms;
    _faderPulseNextEdge = millis() + _faderPulseHalfWidth;
  }
}
.r{}* word consisting of 8 bits.  Command word is clocked out MSB first (i.e. D8
 * is first bit sent)
 *
 * Format of command word (using conventions in datasheet):
 *   ________________________________________________________________________
 *  |   D1   |   D2   |   D3   |   D4   |   D5   |   D6   |   D7   |    D8   |
 *   ————————————————————————
 *   ________________________________________________________________________
 *  |     LED1 CMD    |    LED2 CMD     |    LED3 CMD     |   2X   | LatchOK |
 *   ————————————————————————
 *
 *   LED{1,2,3} CMD –
 *       00 – LED off
 *       01 – LED on (max bright)
 *       10 – LED fade up   (start at min bright)
 *       11 – LED fade down (start at max bright)
 *
 *   2X – Double fade speed
 *       0 – 1X fade speed, each pulse on SI line steps brightness by 1/128th.
 *       1 – 2X fade speed, each pulse on SI line steps brightness by 1/64th.    
 *
 *   LatchOK – Enable latch.  Set to 0 to insert ‘white space’ in the serial
 *             chain.  If set to 0, the entire CMD is ignored.
 *       0 – Do not latch this CMD when Latch is thrown.
 *       1 – Latch CMD as normal when Latch is thrown.
 *
*/
// Push a color value down the strip, setting the latch-enable flag.
void LEDStrip::rgbPush(uint8_t redcmd, uint8_t greencmd, uint8_t bluecmd)
{
  uint8_t cmd = 0;
  uint8_t flags = LATCH;
  if (redcmd >= NONCMD || bluecmd >= NONCMD || greencmd >= NONCMD) return;
  cmd |= (greencmd << 4) & (_BV(5) | _BV(4));
  cmd |= (redcmd << 2) & (_BV(3) | _BV(2));
  cmd |= (bluecmd) & (_BV(1) | _BV(0));
  cmd |= flags & (_BV(6) | _BV(7));
  pushCmd(cmd);
}
void LEDStrip::rgbPush2X(uint8_t redcmd, uint8_t greencmd, uint8_t bluecmd)
{
  uint8_t cmd = 0;
  uint8_t flags = LATCH | SPEED2X;
  if (redcmd >= NONCMD || bluecmd >= NONCMD || greencmd >= NONCMD) return;
  cmd |= (greencmd << 4) & (_BV(5) | _BV(4));
  cmd |= (redcmd << 2) & (_BV(3) | _BV(2));
  cmd |= (bluecmd) & (_BV(1) | _BV(0));
  cmd |= flags & (_BV(6) | _BV(7));
  pushCmd(cmd);
}
void LEDStrip::sPulse()
{
  if (digitalRead(_sPin) == HIGH) {
    //delay(1);
    digitalWrite(_sPin, LOW);
    delayMicroseconds(1000);
    digitalWrite(_sPin, HIGH);
    delayMicroseconds(1000);
  } else {
    //delay(1);
    digitalWrite(_sPin, HIGH);
    delayMicroseconds(1000);
    digitalWrite(_sPin, LOW);
    delayMicroseconds(1000);
  }
}
// Push a blank value down the strip, not setting latch-enable flag.  
// Does not affect the status of a particular LED when latched.  It’s
// like using whitespace.
void LEDStrip::blankPush()
{
  pushCmd(0);
}
void LEDStrip::pushCmd(uint8_t cmd)
{
  shiftOut(_dPin, _clkPin, MSBFIRST, cmd);
}
void LEDStrip::latch()
{
  digitalWrite(_latchPin, HIGH);
  delayMicroseconds(1);  // spec sheet specifies minimum latch pulse of 1us
  digitalWrite(_latchPin, LOW);
}

OK… I still feel yucky. Early to bed for me.. nte folks.. Nite Sam
-me

ps. I just got an IM from my freind carl. He’s on a boat in the middle of the baltic ocean.. 1AM and still sunny there… technology is wonderful

wednesday night – just home

It’s 1:53am .. I just got home from a day long drive down to Hawthorne NY. I left here at 3:30 this morning .. It’s been a long, long day. I’ve got some sort of virus.. I feel yucky.. but all in all it was a good day. Max, Jessie Mason and Tessa drove up 30 seconds after I got here. Their evening is just beginning. I’m Glad to be home. Now off to sleep. Nite all. Nite Sam
-me

Monday midday – pictures from yesterday

Ahhh.. I have momentary bandwidth.. here are the pictures from yesterday… Here are some pictures from Gabe’s MMU Cougars Lacrosse game yesterday.. they won the championship !!!!!  I love watching Gout on the field.. note he was the only one sporting purple horns and a mustache !

I left vermont about 4:30 headed for boston… got to my folks about 4:30. We had a great dinner. My dad made his signature batchelors spaggetti .. and my mom made her prized apple tart. You can’t get more loved than that !


It was a great visit. I’m now on a break at a meeting in Boston.. Gotta pay attention now. More later.. TTYL folks… bye Sam
-me

Saturday night – Jam for Sam

Tonight was the second annual Jam for Sam

fundraiser at Talent Skate Park. The Jam had been organized by Sam T

and the Friends of Sam kids.   The money raised in this Jam is being

used to fund the drilling of water wells and other basic quality of

life improvements in the Cambodian Village of Krang Biang  The Friends

of Sam folks learned of the needs in Krang Biang through an article

about our cambodian freind Khem in Williston.

There

were a ton of kids there tonight.. Our thanks go out ot all the kids in

Freinds of Sam, their parent helpers and the fine folks at Talent. ..

The FoS kids coordinated food and drink. they had a ton of pizza and

baked stuff.

I…. includign jam for sam cookies and cupcakes !

Here’s our lovely hostest Hannah

and lovely host David… standing here with Khem, who’s helping us get

the money to the village in Cambodia where she was born.

There

was a bunch of info on Khem and her cambodian village. it’s a great

story hearing how Khem reunited with her family after so many years !

We also had info about our Sam…

… including organ donor info .. one of our favorite causes .. !

Sam

was very much present tonight.. Many.mnay of the kids had on Sam T

shoirts… if they didnt have them, Talent still sells them.. .!

Sam

T had really been the organizer behhind this and the last years Jam..

his band provided most of the music.. They had some great stuff. Allman

borthers, The Fead.. and newwer stuff. some realllly great Jams !

The place was full of skaters.. and folks watching the skaters.. It was really jumping !

Between band setsm Sumner did the DJ-ing.. he’s really very good !

I liked seeing so many really young kids there.. Avery was helping wth Senyah..

Phil

L came in with some custom painted grip tape he’d made. He hand cut

this stencil of sam It looked awesome. We auctioned it off and made

soemthing like 35 dollars !

I

was showing folks the book that Max and I had bought Gabe at maker’s

faure last week. Dave W and I agtreeed that we have to build it.. Gabe

and I are going to start getting it ready !  Speaking of Max.. he

showed up in town this afternoon. He showed up for the Jam too.. but

somehow I missed getting his picture I was glad to have my ahole familt

there !

It

was a great success tonight.. by 9 folks were starting to clear out. We

still had some  pizza and backed goods. We packed the leftovers in the

car.. and diane drove them over to Spectum Services for the homeless..

Meanwhile I took Kristin and Gabe home..    Gab’es gotta get a good

nights sleep. his LAX playoffs are tomorrow !

It was a great event.. Sam’s spirit was there everywwhere… !

OK

folks.. I’m falling asleep.. and we have ealry morning Lacrossse

playoffs. So I’m going to bed. Gnite everyone. Gnite Sam.. we’re still

jammin’ for you !
love -me

ps.