Skip to content

Commit

Permalink
Added another boblight example + config file.
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Spitzenpfeil committed May 15, 2012
1 parent cc4b90b commit dd64335
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 0 deletions.
23 changes: 23 additions & 0 deletions V2_demo/examples/boblight_lamp_1_light/boblight_lamp_1_light.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Fix for Arduino IDE
* Normally this could just be in the main source code file
*/

#ifdef V2_1
#define LATCH_LOW PORTB &= ~_BV(PB2)
#define LATCH_HIGH PORTB |= _BV(PB2)
#endif

#ifdef V2_0_d
#define DRIVER_ON PORTB &= ~_BV(PB6)
#define DRIVER_OFF PORTB |= _BV(PB6)
#define LATCH_LOW PORTB &= ~_BV(PB2)
#define LATCH_HIGH PORTB |= _BV(PB2)
#endif

#ifdef V2_0_beta
#define DRIVER_ON PORTB &= ~_BV(PB6)
#define DRIVER_OFF PORTB |= _BV(PB6)
#define LATCH_LOW PORTB &= ~_BV(PB2)
#define LATCH_HIGH PORTB |= _BV(PB2)
#endif
95 changes: 95 additions & 0 deletions V2_demo/examples/boblight_lamp_1_light/boblight_lamp_1_light.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
//#define V2_1
#define V2_0_d
//#define V2_0_beta

#include <stdint.h>
#include <SPI.h>
#include "boblight_lamp_1_light.h"

#define NUM_OF_CHANNELS 3

//Data pin is MOSI (atmega168/328: pin 11. Mega: 51)
//Clock pin is SCK (atmega168/328: pin 13. Mega: 52)
const int ShiftPWM_latchPin = 10;
const bool ShiftPWM_invertOutputs = 0; // if invertOutputs is 1, outputs will be active low. Usefull for common anode RGB led's.

unsigned char maxBrightness = 255;
unsigned char pwmFrequency = 75;
int numRegisters = 3;

#include <ShiftPWM.h> // modified version! - include ShiftPWM.h after setting the pins!

uint8_t values[NUM_OF_CHANNELS]; // boblight input buffer

void setup(void)
{
#ifdef V2_1
DDRB |= _BV(PB2) | _BV(PB3) | _BV(PB5); // set LATCH, MOSI, SCK as outputs
analogWrite(6, 255); // small LEDs off
analogWrite(3, 0); // LED driver chips on
TCCR2B &= ~_BV(CS22); // change TIMER2 prescaler to DIV1 for higher PWM frequency (16kHz instead of 250Hz --> less beating)
TCCR2B |= _BV(CS20);
#endif

#ifdef V2_0_d
DDRB |= _BV(PB2) | _BV(PB3) | _BV(PB5) | _BV(PB6); // set LATCH, MOSI, SCK, OE as outputs
analogWrite(6, 255); // small LEDs off off
DRIVER_ON; // LED driver chips on
#endif

#ifdef V2_0_beta
DDRB |= _BV(PB2) | _BV(PB3) | _BV(PB5) | _BV(PB6); // set LATCH, MOSI, SCK, OE as outputs
DRIVER_ON; // LED driver chips on
#endif

Serial.begin(19200);

//
// ShiftPWM stuff
//
pinMode(ShiftPWM_latchPin, OUTPUT);
SPI.setBitOrder(LSBFIRST);
// SPI_CLOCK_DIV2 is only a tiny bit faster in sending out the last byte.
// SPI transfer and calculations overlap for the other bytes.
SPI.setClockDivider(SPI_CLOCK_DIV2);
SPI.begin();

ShiftPWM.SetAmountOfRegisters(numRegisters);
ShiftPWM.SetAll(0);
ShiftPWM.Start(pwmFrequency, maxBrightness);

uint8_t tmp;
for (tmp = 0; tmp <= 7; tmp++) {
ShiftPWM.SetGroupOf3(tmp, 0, 0, 0);
}
}

void loop(void)
{
uint8_t counter;

WaitForPrefix();

for (counter = 0; counter < NUM_OF_CHANNELS; counter++) {
while (!Serial.available()) ;
values[counter] = Serial.read();
}

for (counter = 0; counter < 8; counter++) {
ShiftPWM.SetGroupOf3(counter, values[0],
values[1],
values[2]);
}

}

//boblightd needs to send 0x55 0xAA before sending the channel bytes
void WaitForPrefix(void)
{
uint8_t first = 0, second = 0;
while (second != 0x55 || first != 0xAA) {
while (!Serial.available()) ;
second = first;
first = Serial.read();
}
}
8 changes: 8 additions & 0 deletions V2_demo/examples/boblight_lamp_1_light/indent.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

indent -linux *.pde
indent -linux *.ino
indent -linux *.cpp
indent -linux *.c
indent -linux *.h

13 changes: 13 additions & 0 deletions V2_demo/examples/boblight_lamp_1_light/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

http://code.google.com/p/boblight/
http://blogger.xs4all.nl/loosen/


Some documentation:
-------------------

http://code.google.com/p/boblight/w/list


This demo also requires the modified version of the ShiftPWM library installed.

45 changes: 45 additions & 0 deletions setup-files/boblight/1_light.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# copy to /etc/boblight.conf

[global]
interface 127.0.0.1
port 19333

[device]
name rgb_led_ring
output /dev/ttyUSB0
channels 3
type momo
interval 20000
rate 19200
prefix 55 AA

[color]
name red
rgb FF0000
adjust 1.0
gamma 1.0

[color]
name green
rgb 00FF00
adjust 0.4
gamma 2.0

[color]
name blue
rgb 0000FF
adjust 0.4
gamma 2.0

[color]
name white
rgb FFFFFF

[light]
name one
color red rgb_led_ring 1
color green rgb_led_ring 2
color blue rgb_led_ring 3
hscan 25 75
vscan 25 75

Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# copy to /etc/boblight.conf

[global]
interface 127.0.0.1
port 19333
Expand Down Expand Up @@ -96,3 +98,4 @@ color green rgb_led_ring 23
color blue rgb_led_ring 24
hscan 25 75
vscan 25 75

0 comments on commit dd64335

Please sign in to comment.