Author Topic: USB Mood Lamp that Sleeps When the Computer Does  (Read 4073 times)

dmcinnes

  • Newbie
  • *
  • Posts: 21
USB Mood Lamp that Sleeps When the Computer Does
« on: February 21, 2013, 10:01:22 pm »
Hey I've made a mood lamp with the RGB LED shield and an IKEA frosted glass lamp shade.

My idea was to plug it into a USB hub and only light up when my computer was connected and awake, kind of a "the doctor is in" lamp.

Check out a video of it in action:
http://www.youtube.com/watch?v=95n7XkzuqnQ

Here's the code:
https://github.com/dmcinnes/led_usb_lamp

I ran into some problems out the gate because the VUSB software driver requires disabling the timer interrupt (not sure why). I ended up faking the millis() call and not using delay() at all. The DigiRGB library uses ISR which seems to also depend on the timer interrupt so I ended up pulling that code in my file and calling it directly in the loop.

When a USB device is connected to a Host computer the host sents frame pulses to the devices every few milliseconds. With some configuration the VUSB library will increments a "usbSofCount" variable every time it sees a frame pulse. My code watches these and fades the LED away once it stops updating and turns the light back on when sees frame pulses again.

The code aint pretty but it works :)

Bluebie

  • Sr. Member
  • ****
  • Posts: 486
Re: USB Mood Lamp that Sleeps When the Computer Does
« Reply #1 on: February 22, 2013, 03:07:25 pm »
For a simpler alternative you might consider totally ditching the USB libraries and just watching for the SOF pulse yourself! To detect activity on USB, you just need to watch for data coming through on either of the two USB data lines. You could do this with the pin change interrupt.


I'm still puzzling over why the USB libraries included with digispark disable the timer. Maybe it's that the timer overflow interrupt in wiring.c is so complicated. I have my own timer library which only does one variable increment in the overflow interrupt - maybe I can hack this core to use a version of my own code which might not introduce too much latency for USB libraries to work with it.