- Tue Mar 25, 2008 1:59 am
#45315
Hi All,
I'm recently working with LM4970, audio synchronized LED driver.
I wrote an Arduino code, based on BlinkM's example, which sets up LM4970 via I2C commands.
It looks fine but my LM4970 never worked.
Could you give me an advise or test it if you have them??
tom
LM4970_funcs.h:
update:
I'm recently working with LM4970, audio synchronized LED driver.
I wrote an Arduino code, based on BlinkM's example, which sets up LM4970 via I2C commands.
It looks fine but my LM4970 never worked.
Could you give me an advise or test it if you have them??
tom
Code: Select all
// SDA -- Analog In 4
// SCL -- Analog In 5
#include "Wire.h"
#include "LM4970_funcs.h"
#define LM4970_ARDUINO_POWERED 1
int lm4970_addr = LM4970_ADDR_0;
int ledPin = 13;
void setup()
{
pinMode(ledPin, OUTPUT);
if( LM4970_ARDUINO_POWERED ) {
LM4970_beginWithPower();
} else {
LM4970_begin();
}
Serial.begin(19200);
Serial.println("LM4970 ready");
digitalWrite(ledPin, HIGH); // say we're working on it
#if 1 // audio synchronization mode
LM4970_setMode(lm4970_addr);
LM4970_setFreq(lm4970_addr);
LM4970_setPattern(lm4970_addr);
LM4970_setLEDDrive(lm4970_addr);
LM4970_setGain(lm4970_addr);
#elif 0 // audio synchronization mode (raw data ver according to sparkfun pdf)
byte cmd[] = {0x04, 0x50, 0x60, 0xBF, 0xF2};
LM4970_sendCmd(lm4970_addr, cmd, 5);
#else // i2c led mode
LM4970_setMode(lm4970_addr, false, false, false);
LM4970_setPattern(lm4970_addr, true, true, true, true);
#endif
digitalWrite(ledPin, LOW);
}
void loop()
{
}
LM4970_funcs.h:
Code: Select all
[/size]#define DEBUG
#include <Wire.h>
static byte LM4970_ADDR_0 = 0xF4; // with ADR pin LOW
static byte LM4970_ADDR_1 = 0xF6; // with ADR pin HIGH
// Call this first (when powering LM4970 from a power supply)
static void LM4970_begin()
{
Wire.begin(); // join i2c bus (address optional for master)
}
// General version of LM4970_beginWithPower().
// Call this first when LM4970 is plugged directly into Arduino
static void LM4970_beginWithPowerPins(byte pwrpin, byte gndpin)
{
DDRC |= _BV(pwrpin) | _BV(gndpin);
PORTC &=~ _BV(gndpin);
PORTC |= _BV(pwrpin);
delay(100); // wait for things to stabilize
Wire.begin();
}
// Call this first when LM4970 is plugged directly into Arduino
static void LM4970_beginWithPower()
{
LM4970_beginWithPowerPins( PC3, PC2 );
}
// sends a generic command
static void LM4970_sendCmd(byte addr, byte* cmd, int cmdlen)
{
Wire.beginTransmission(addr);
for( byte i=0; i<cmdlen; i++) {
Wire.send((int)cmd[i]);
#ifdef DEBUG
Serial.print(cmd[i], HEX);
Serial.print(' ');
#endif
}
Wire.endTransmission();
delay(50);
}
static void LM4970_setMode(byte addr, boolean shutdown = false, boolean reset = false, boolean audioSync = true)
{
byte cmd = 0;
cmd |= shutdown << 0;
cmd |= reset << 1;
cmd |= audioSync << 2;
LM4970_sendCmd(addr, &cmd, 1);
}
static void LM4970_setFreq(byte addr, byte pwmFreq = 0 /* 0 to 3 (15k, 60, 7, 4 Hz) */, byte highPass = 2 /* 0 to 3 (3.5k, 6.3k, 6.3k, 8.9k Hz) */)
{
byte cmd = 0x40;
cmd |= pwmFreq << 0;
cmd |= highPass << 3;
LM4970_sendCmd(addr, &cmd, 1);
}
static void LM4970_setPattern(byte addr, boolean i2cMode = false, boolean led1 = false /* only i2c mode*/, boolean led2 = false /* only i2c mode*/, boolean led3 = false /* only i2c mode*/)
{
byte cmd = 0x60;
cmd |= i2cMode << 0;
cmd |= led1 << 1;
cmd |= led2 << 2;
cmd |= led3 << 3;
LM4970_sendCmd(addr, &cmd, 1);
}
static void LM4970_setLEDDrive(byte addr, byte led1 = 3 /* 0 to 3 (0.66x, 1x,1.33x, 2x) */, byte led2 = 3 /* 0 to 3 (0.66x, 1x,1.33x, 2x) */, byte led3 = 3 /* 0 to 3 (0.66x, 1x,1.33x, 2x) */)
{
byte cmd = 0x80;
cmd |= led1 << 0;
cmd |= led2 << 2;
cmd |= led3 << 4;
LM4970_sendCmd(addr, &cmd, 1);
}
static void LM4970_setGain(byte addr, byte mid = 2 /* 0 to 4 (min to max) */, byte sum = 6 /* 0 to 6 (-11, -6.5, 0, 3.5, 6, 10, 12db) */)
{
byte cmd = 0x80;
cmd |= mid << 0;
cmd |= sum << 3;
LM4970_sendCmd(addr, &cmd, 1);
}
update:
Code: Select all
should be
static byte LM4970_ADDR_0 = 0xF4; // with ADR pin LOW
static byte LM4970_ADDR_1 = 0xF6; // with ADR pin HIGH
Code: Select all
Still not working, though.static byte LM4970_ADDR_0 = 0x7A; // with ADR pin LOW
static byte LM4970_ADDR_1 = 0x7B; // with ADR pin HIGH