mirror of
https://github.com/brmlab/ledbar.git
synced 2025-06-09 05:14:03 +02:00
Convert arduino autonomous.pde to new TLC59116, single-TLC configuration
This commit is contained in:
parent
2763d82908
commit
a78e231296
4 changed files with 79 additions and 29 deletions
|
@ -1,7 +1,6 @@
|
|||
These sketches require the Tlc5940 library, with NUM_TLCS set to 23.
|
||||
You may also need to reduce HardwareSerial RX_BUFFER_SIZE to something
|
||||
like 16 in order to free up more RAM.
|
||||
|
||||
autonomous.pde: This is autonomous LED controller that implements several
|
||||
simple color cycling algorithms directly on Ardiuno - no host controller
|
||||
is required. All LEDs have the same color. Useful for testing.
|
||||
|
||||
controlled.pde: Listens to a byte stream on serial. The byte stream should
|
||||
contain one R,G,B tribyte per LED, sent repeatedly.
|
||||
|
|
10
arduino/autonomous/Makefile
Normal file
10
arduino/autonomous/Makefile
Normal file
|
@ -0,0 +1,10 @@
|
|||
ARDUINO_DIR = /usr/share/arduino
|
||||
|
||||
BOARD_TAG = pro5v
|
||||
ARDUINO_PORT = /dev/ttyUSB0
|
||||
|
||||
TARGET = autonomous
|
||||
|
||||
ARDUINO_LIBS = Wire Wire/utility
|
||||
|
||||
include /usr/share/arduino/Arduino.mk
|
|
@ -1,8 +1,8 @@
|
|||
#include "Tlc5940.h"
|
||||
#include "../ledbar.h"
|
||||
|
||||
#define CH 3
|
||||
|
||||
#define TLCCH(tlc_num, ch_num) ((tlc_num)*16 + (ch_num))
|
||||
#define TLCCH(tlc_num, ch_num) (ch_num) /* FIXME */
|
||||
|
||||
unsigned int xr1 = 19543;
|
||||
|
||||
|
@ -13,27 +13,23 @@ int cpin[][CH] = {
|
|||
{TLCCH(0, 12), TLCCH(0, 11),TLCCH(0, 10)},
|
||||
{TLCCH(0, 15),TLCCH(0, 14),TLCCH(0, 13)},
|
||||
|
||||
#if 0
|
||||
{TLCCH(1, 2), TLCCH(1, 1), TLCCH(1, 0)},
|
||||
{TLCCH(1, 5), TLCCH(1, 4), TLCCH(1, 3)},
|
||||
{TLCCH(1, 8), TLCCH(1, 7), TLCCH(1, 6)},
|
||||
{TLCCH(1, 12), TLCCH(1, 11), TLCCH(1, 10)},
|
||||
{TLCCH(1, 15), TLCCH(1, 14), TLCCH(1, 13)},
|
||||
#endif
|
||||
};
|
||||
#define cpinsets (sizeof(cpin)/sizeof(cpin[0]))
|
||||
|
||||
/* cca 2.7ohm resistor per channel */
|
||||
int cmax[cpinsets][CH] = {
|
||||
{ 1600, 4000, 2200 },
|
||||
{ 1600, 4000, 2200 },
|
||||
{ 1600, 4000, 2200 },
|
||||
{ 1600, 3900, 2000 },
|
||||
{ 1600, 3700, 3000 },
|
||||
|
||||
{ 1600, 4000, 2200 },
|
||||
{ 1600, 4000, 2200 },
|
||||
{ 1600, 3400, 3000 },
|
||||
{ 1600, 4000, 2200 },
|
||||
{ 1600, 3400, 3000 },
|
||||
{ 100, 250, 138 },
|
||||
{ 100, 250, 138 },
|
||||
{ 100, 250, 138 },
|
||||
{ 100, 240, 230 },
|
||||
{ 100, 230, 188 },
|
||||
};
|
||||
int c[cpinsets][CH];
|
||||
|
||||
|
@ -42,13 +38,14 @@ int wait = 10;
|
|||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
/* Call Tlc.init() to setup the tlc.
|
||||
You can optionally pass an initial PWM value (0 - 4095) for all channels.*/
|
||||
Tlc.init();
|
||||
Ledbar.begin(B1100000);
|
||||
int i = 0, led = 0;
|
||||
for (led = 0; led < cpinsets; led++)
|
||||
for (i = 0; i < CH; i++)
|
||||
for (led = 0; led < cpinsets; led++) {
|
||||
for (i = 0; i < CH; i++) {
|
||||
c[led][i] = cmax[led][i] / 2;
|
||||
Ledbar.setPinMode(cpin[led][i], LPM_PWM);
|
||||
}
|
||||
}
|
||||
xr1 += analogRead(0);
|
||||
}
|
||||
|
||||
|
@ -164,8 +161,6 @@ void grey(int led)
|
|||
|
||||
void loop()
|
||||
{
|
||||
Tlc.clear();
|
||||
|
||||
int led;
|
||||
for (led = 0; led < cpinsets; led++) {
|
||||
//random_walk(led);
|
||||
|
@ -179,15 +174,11 @@ void loop()
|
|||
for (i = 0; i < CH; i++) {
|
||||
for (led = 0; led < cpinsets; led++) {
|
||||
//Serial.print(cpin[led][i], DEC); Serial.print("="); Serial.print(c[led][i], DEC); Serial.print("/"); Serial.print(cmax[led][i], DEC); Serial.print(" ");
|
||||
Tlc.set(cpin[led][i], c[led][i]);
|
||||
Ledbar.setPinPWM(cpin[led][i], c[led][i]);
|
||||
}
|
||||
}
|
||||
//Serial.print(NUM_TLCS, DEC);
|
||||
//Serial.println();
|
||||
|
||||
/* Tlc.update() sends the data to the TLCs. This is when the LEDs will
|
||||
actually change. */
|
||||
Tlc.update();
|
||||
|
||||
delay(wait);
|
||||
}
|
50
arduino/ledbar.h
Normal file
50
arduino/ledbar.h
Normal file
|
@ -0,0 +1,50 @@
|
|||
/* Generic ledbar library taking care of I2C Arduino communication
|
||||
* with TLC59116. */
|
||||
|
||||
#include <Wire.h>
|
||||
|
||||
enum LedbarPinMode {
|
||||
LPM_OFF,
|
||||
LPM_ON,
|
||||
LPM_PWM,
|
||||
LPM_GRPPWM,
|
||||
};
|
||||
|
||||
class Ledbar {
|
||||
public:
|
||||
void begin(unsigned char address); /* 7-bit TLC address */
|
||||
/* pin is 0 .. 15 */
|
||||
void setPinMode(int pin, enum LedbarPinMode pinMode);
|
||||
void setPinPWM(int pin, unsigned char dutyCycle);
|
||||
private:
|
||||
unsigned char address;
|
||||
unsigned char rawPinModes[4];
|
||||
} Ledbar;
|
||||
|
||||
void Ledbar::begin(unsigned char address_)
|
||||
{
|
||||
address = address_;
|
||||
memset(&rawPinModes, 0, sizeof(rawPinModes));
|
||||
|
||||
Wire.begin();
|
||||
Wire.beginTransmission(address);
|
||||
Wire.write(0x00); // reg 0
|
||||
Wire.write(0x01); // broadcast on, [5bit]=0 turns on oscillator
|
||||
Wire.endTransmission();
|
||||
}
|
||||
|
||||
void Ledbar::setPinMode(int pin, enum LedbarPinMode pinMode)
|
||||
{
|
||||
Wire.beginTransmission(address);
|
||||
rawPinModes[pin / 4] &= ~(0x3 << (pin % 4 * 2));
|
||||
rawPinModes[pin / 4] |= (pinMode << (pin % 4 * 2));
|
||||
Wire.write(0x14 + pin / 4); Wire.write(rawPinModes[pin / 4]);
|
||||
Wire.endTransmission();
|
||||
}
|
||||
|
||||
void Ledbar::setPinPWM(int pin, unsigned char dutyCycle)
|
||||
{
|
||||
Wire.beginTransmission(address);
|
||||
Wire.write(0x2 + pin); Wire.write(dutyCycle);
|
||||
Wire.endTransmission();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue