From c0001a5cf7469c1b7e0daa1270175a25474356d4 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Sat, 30 Jun 2012 19:24:16 +0200 Subject: [PATCH] arduino: Update controlled for new TLCs --- arduino/controlled.pde | 80 ------------------------------- arduino/controlled/Makefile | 10 ++++ arduino/controlled/controlled.ino | 34 +++++++++++++ 3 files changed, 44 insertions(+), 80 deletions(-) delete mode 100644 arduino/controlled.pde create mode 100644 arduino/controlled/Makefile create mode 100644 arduino/controlled/controlled.ino diff --git a/arduino/controlled.pde b/arduino/controlled.pde deleted file mode 100644 index fb91985..0000000 --- a/arduino/controlled.pde +++ /dev/null @@ -1,80 +0,0 @@ -#include "Tlc5940.h" - -#define CH 3 - -#define TLCCH(tlc_num, ch_num) ((tlc_num)*16 + (ch_num)) - -int cpin[][CH] = { - {TLCCH(0, 2), TLCCH(0, 1), TLCCH(0, 0)}, - {TLCCH(0, 5), TLCCH(0, 4), TLCCH(0, 3)}, - {TLCCH(0, 8), TLCCH(0, 7), TLCCH(0, 6)}, - {TLCCH(0, 12), TLCCH(0, 11),TLCCH(0, 10)}, - {TLCCH(0, 15),TLCCH(0, 14),TLCCH(0, 13)}, - - {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)}, -}; -#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 }, -}; -int c[cpinsets][CH]; - -int wait = 10; - -void setup() -{ - Serial.begin(38400); - /* Call Tlc.init() to setup the tlc. - You can optionally pass an initial PWM value (0 - 4095) for all channels.*/ - Tlc.init(); - int i = 0, led = 0; - for (led = 0; led < cpinsets; led++) - for (i = 0; i < CH; i++) - c[led][i] = cmax[led][i]; -} - -/* One iteration of constant brightest white (useful for tuning constants for particular LEDs). */ -void white(int led) -{ - int i; - int mask = 1|2|4; // R, G, B - for (i = 0; i < CH; i++) { - c[led][i] = mask & (1 << i) ? cmax[led][i] : 0; - } -} - -void loop() -{ - Tlc.clear(); - - int led, i; - for (led = 0; led < cpinsets; led++) { - for (i = 0; i < CH; i++) { - while (!Serial.available()); - unsigned long s = (unsigned char) Serial.read(); -// Serial.print(s, DEC); -// Serial.print(" "); - Tlc.set(cpin[led][i], s * cmax[led][i] / 256); - } - } -// Serial.println(); - - Tlc.update(); -} - diff --git a/arduino/controlled/Makefile b/arduino/controlled/Makefile new file mode 100644 index 0000000..605aa5e --- /dev/null +++ b/arduino/controlled/Makefile @@ -0,0 +1,10 @@ +ARDUINO_DIR = /usr/share/arduino + +BOARD_TAG = pro5v +ARDUINO_PORT = /dev/ttyUSB0 + +TARGET = controlled + +ARDUINO_LIBS = Wire Wire/utility + +include /usr/share/arduino/Arduino.mk diff --git a/arduino/controlled/controlled.ino b/arduino/controlled/controlled.ino new file mode 100644 index 0000000..06d235d --- /dev/null +++ b/arduino/controlled/controlled.ino @@ -0,0 +1,34 @@ +#include "../ledbar.h" + +class Ledbar lb[NUM_TLCS]; +int c[cpinsets][CH]; + +int wait = 10; + +void setup() +{ + Serial.begin(38400); + int i = 0, led = 0; + for (i = 0; i < NUM_TLCS; i++) + lb[i].begin(B1100000 | i << 1); + for (led = 0; led < cpinsets; led++) { + for (i = 0; i < CH; i++) { + c[led][i] = cmax[led][i] / 2; + lb[cpin[led][i] >> 4].setPinMode(cpin[led][i] & 0xf, LPM_PWM); + } + } +} + +void loop() +{ + int led, i; + for (led = 0; led < cpinsets; led++) { + for (i = 0; i < CH; i++) { + while (!Serial.available()); + unsigned long s = (unsigned char) Serial.read(); + // Serial.print(cpin[led][i], DEC); Serial.print("="); Serial.print(s, DEC); Serial.print("/"); Serial.print(cmax[led][i], DEC); Serial.print(" "); + lb[cpin[led][i] >> 4].setPinPWM(cpin[led][i] & 0xf, s * cmax[led][i] / 256); + } + } + // Serial.println(); +}