L'instructables mi serviva più che altro solo ed esclusivamente per il circuito..
Comunque, smanettando nella libreria (e leggendo i commenti del file configuration), ho scoperto che tutti i pin vengono dichiarati nella cartella "pinouts" in base alle schede utilizzate.
Ho quindi aperto il file "Arduino_Mega.h" ed ho modificato i pin nel seguente modo:
/* Copyright (c) 2009 by Alex Leone <acleone ~AT~ gmail.com>
This file is part of the Arduino TLC5940 Library.
The Arduino TLC5940 Library is free software: you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
The Arduino TLC5940 Library is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with The Arduino TLC5940 Library. If not, see
<http://www.gnu.org/licenses/>. */
#ifndef ARDUINO_MEGA_H
#define ARDUINO_MEGA_H
/** \file
SPI and timer pins for the Arduino Mega. Don't edit these. All
changeable pins are defined in tlc_config.h */
/** VPRG (Mega pin 12) -> VPRG (TLC pin 27) */
#define DEFAULT_VPRG_PIN PB6
#define DEFAULT_VPRG_PORT PORTB
#define DEFAULT_VPRG_DDR DDRB
/** XERR (Mega pin 13) -> XERR (TLC pin 16) */
#define DEFAULT_XERR_PIN PB7
#define DEFAULT_XERR_PORT PORTB
#define DEFAULT_XERR_DDR DDRB
#define DEFAULT_XERR_PINS PINB
/** SIN (Mega pin 11) -> SIN (TLC pin 26) */
#define DEFAULT_BB_SIN_PIN PB5
#define DEFAULT_BB_SIN_PORT PORTB
#define DEFAULT_BB_SIN_DDR DDRB
/** SCLK (Mega pin 10) -> SCLK (TLC pin 25) */
#define DEFAULT_BB_SCLK_PIN PB4
#define DEFAULT_BB_SCLK_PORT PORTB
#define DEFAULT_BB_SCLK_DDR DDRB
/** MOSI (Mega pin 11) -> SIN (TLC pin 26) */
#define TLC_MOSI_PIN PB5
#define TLC_MOSI_PORT PORTB
#define TLC_MOSI_DDR DDRB
/** SCK (Mega pin 10) -> SCLK (TLC pin 25) */
#define TLC_SCK_PIN PB4
#define TLC_SCK_PORT PORTB
#define TLC_SCK_DDR DDRB
// SS (Mega pin 53)
/** SS will be set to output as to not interfere with SPI master operation.
If you have changed the pin-outs and the library doesn't seem to work
or works intermittently, make sure this pin is set correctly. This pin
will not be used by the library other than setting its direction to
output. */
#define TLC_SS_PIN PB0
#define TLC_SS_DDR DDRB
/** OC1A (Mega pin 9) -> XLAT (TLC pin 24) */
#define XLAT_PIN PH6
#define XLAT_PORT PORTH
#define XLAT_DDR DDRH
/** OC1B (Mega pin 8) -> BLANK (TLC pin 23) */
#define BLANK_PIN PH5
#define BLANK_PORT PORTH
#define BLANK_DDR DDRH
/** OC2B (Mega pin 7) -> GSCLK (TLC pin 18) */
#define GSCLK_PIN PH4
#define GSCLK_PORT PORTH
#define GSCLK_DDR DDRH
#endif
Son quindi tornato nel file configuration e, seguendo i valori inseriti nel file Arduino_Mega.h, ho modificato di conseguenza i seguenti valori:
/* ------------------------ START EDITING HERE ----------------------------- */
/** Number of TLCs daisy-chained. To daisy-chain, attach the SOUT (TLC pin 17)
of the first TLC to the SIN (TLC pin 26) of the next. The rest of the pins
are attached normally.
\note Each TLC needs it's own IREF resistor */
#ifndef NUM_TLCS
#define NUM_TLCS 2
#endif
/** Determines how data should be transfered to the TLCs. Bit-banging can use
any two i/o pins, but the hardware SPI is faster.
- Bit-Bang = TLC_BITBANG
- Hardware SPI = TLC_SPI (default) */
#define DATA_TRANSFER_MODE TLC_BITBANG
/* This include is down here because the files it includes needs the data
transfer mode */
#include "pinouts/chip_includes.h"
/* Set DATA_TRANSFER_MODE to TLC_BITBANG and change the pins below if you need
to use different pins for sin and sclk. The defaults are defined in
pinouts/ATmega_xx8.h for most Arduino's. */
#if DATA_TRANSFER_MODE == TLC_BITBANG
/** SIN (TLC pin 26) */
#define SIN_PIN DEFAULT_BB_SIN_PIN
#define SIN_PORT DEFAULT_BB_SIN_PORT
#define SIN_DDR DEFAULT_BB_SIN_DDR
/** SCLK (TLC pin 25) */
#define SCLK_PIN DEFAULT_BB_SCLK_PIN
#define SCLK_PORT DEFAULT_BB_SCLK_PORT
#define SCLK_DDR DEFAULT_BB_SCLK_DDR
#endif
/** If more than 16 TLCs are daisy-chained, the channel type has to be uint16_t.
Default is uint8_t, which supports up to 16 TLCs. */
#define TLC_CHANNEL_TYPE uint8_t
/** Determines how long each PWM period should be, in clocks.
\f$\displaystyle f_{PWM} = \frac{f_{osc}}{2 * TLC\_PWM\_PERIOD} Hz \f$
\f$\displaystyle TLC\_PWM\_PERIOD = \frac{f_{osc}}{2 * f_{PWM}} \f$
This is related to TLC_GSCLK_PERIOD:
\f$\displaystyle TLC\_PWM\_PERIOD =
\frac{(TLC\_GSCLK\_PERIOD + 1) * 4096}{2} \f$
\note The default of 8192 means the PWM frequency is 976.5625Hz */
#define TLC_PWM_PERIOD 8192
/** Determines how long each period GSCLK is.
This is related to TLC_PWM_PERIOD:
\f$\displaystyle TLC\_GSCLK\_PERIOD =
\frac{2 * TLC\_PWM\_PERIOD}{4096} - 1 \f$
\note Default is 3 */
#define TLC_GSCLK_PERIOD 3
/** Enables/disables VPRG (TLC pin 27) functionality. If you need to set dot
correction data, this needs to be enabled.
- 0 VPRG is not connected. <em>TLC pin 27 must be grounded!</em> (default)
- 1 VPRG is connected
\note VPRG to GND inputs grayscale data, VPRG to Vcc inputs dot-correction
data */
#define VPRG_ENABLED 0
/** Enables/disables XERR (TLC pin 16) functionality to check for shorted/broken
LEDs
- 0 XERR is not connected (default)
- 1 XERR is connected
\note XERR is active low */
#define XERR_ENABLED 0
/* You can change the VPRG and XERR pins freely. The defaults are defined in
the chip-specific pinouts: see pinouts/ATmega_xx8.h for most Arduino's. */
#if VPRG_ENABLED
/** VPRG (TLC pin 27) */
#define VPRG_PIN DEFAULT_VPRG_PIN
#define VPRG_PORT DEFAULT_VPRG_PORT
#define VPRG_DDR DEFAULT_VPRG_DDR
#endif
#if XERR_ENABLED
/** XERR (TLC pin 16) */
#define XERR_PIN DEFAULT_XERR_PIN
#define XERR_PORT DEFAULT_XERR_PORT
#define XERR_DDR DEFAULT_XERR_DDR
#define XERR_PINS DEFAULT_XERR_PINS
#endif
/* ------------------------- STOP EDITING HERE ----------------------------- */
Essendoci come "valore" dei pin la dicitura "DEFAULT_XXX_PINS", che corrisponde esattamente alla dichiarazione define nel file Arduino_Mega.h, nel quale ho già modificato i pin a mio piacimento, nel file configuration ho lasciato invariate queste voci perchè deduco che, quando andrò a selezionare nell'IDE la scheda da programmare, la libreria andrà direttamente a "pescare" i pin dal file modificato nella cartella pinouts.
Mi son quindi limitato ad:
- Indicare il numero di integrati;
- cambiare la comunicazione da SPI a BITBANG
inoltre, avendo mantenuto disabilitati i pin VPRG (che va messo a massa) ed il pin 16, significa che i pin PWM 12 e 13 di Arduino saranno comunque utilizzabili dal codice.
Che ne pensi di quel che ho fatto?