#include // for I2C // defines for LM4970 #define LM4970_ADDR_0 0x7A // first 7 bits of address 0 (ADR = LOW) #define LM4970_ADDR_1 0x7B // first 7 bits of address 1 (ADR = HIGH) #define LM4970_MODE_NORM 0x00 // power up, normal I2C, no random #define LM4970_MODE_RAND 0x04 // power up, normal I2C, random #define LM4970_FREQ 0x50 // 6.3kHz High Pass / 15kHz PWM #define LM4970_PATT_AUDIO 0x60 // pattern gen by audio input #define LM4970_PATT_I2C 0x61 // pattern gen by I2C - all off #define LM4970_CURR 0xAA // 1x current (21mA)on LED 1-3 #define LM4970_GAIN 0xEA // gain = 10dB / midband = medium byte LM4970_Address = LM4970_ADDR_0; // using address 0 (ADR = LOW) void setup() { Wire.begin(); LM4970_Hello(); // light up some LEDs in I2C mode LM4970_Init(); // set for audio control of LEDs } void loop(){ } void LM4970_Init(){ // Init based on #defines above Wire.beginTransmission(LM4970_Address); Wire.write(LM4970_MODE_NORM); // set the mode Wire.write(LM4970_FREQ); // set the freq Wire.write(LM4970_PATT_AUDIO); // set the pattern Wire.write(LM4970_CURR); // set the current Wire.write(LM4970_GAIN); // set the gain Wire.endTransmission(); delay(5); // safety - may not be needed } void LM4970_I2C_Led(boolean LED1,boolean LED2,boolean LED3){ // I2C control of LEDs byte pattern = LM4970_PATT_I2C; // pattern set to I2C control - all off pattern |= LED1 << 1; // shift in status for LED1 pattern |= LED2 << 2; // shift in status for LED2 pattern |= LED3 << 3; // shift in status for LED3 Wire.beginTransmission(LM4970_Address); Wire.write(pattern); // send the command for the LEDs to light Wire.write(LM4970_CURR); // set the current Wire.endTransmission(); delay(5); // safety - may not be needed } void LM4970_Hello(){ LM4970_I2C_Led(true,false,false); // turn on LED-1 delay(500); LM4970_I2C_Led(false,true,false); // turn on LED-2 delay(500); LM4970_I2C_Led(false,false,true); // turn on LED-1 delay(500); LM4970_I2C_Led(true,true,true); // turn on all 3 delay(1000); LM4970_I2C_Led(false,false,false); // turn em off delay(1000); }