/* Arduino byterface with Rachel's Electronics Disco Chip Breakout of the Texas Instrument LM4970 'Boomer' Developed by Joel Murphy for Rachel's Electronics Spring '010. Serial protocol for the LM4970 is I2C. >>>> NOTE THERE IS AN ERROR IN THE DATASHEET! >>>> THE MSB OF PATTERN SELECT REGISTER SHOULD BE 0 INSTEAD OF 1 >>>> NOTE THAT IF PATTERN SELECT MSB IS SET IT GETS CONFUSED WITH THE GAIN SELECT REGISTER! The LM4970 is a 3 channel LED sink driver. It will drive three discrete LEDs or one common anode RGB LED There are two general modes: Audio Syncronization mode and I2C color control mode In Audio Sync mode, the device drives PWM out L1,L2,L3 pins based on amplitude of audio signal Low Band L1 Mid Band L2 High Band L3 In I2C color control mode, the PWM signals on L1,L2,L3 are controlled by Arduino. Use I2C to enable/disable LED channels, and to set current output. This code sets up the LM4970 in I2C control mode and scrolls through the color combinations. Visit Rachel's for more info, like the datasheet, and links to cool projects. http://www.rachelselectronics.com/products/discochip/ (un)Licenced under Creative Commons Attribution Share-Alike */ // I2C is a two wire, synchronous serial communication protocol. // more about I2C: http://www.embedded.com/story/OEG20010718S0073 // writing 'Wire.begin(); initializes I2C hardware on Atmel and defines pins: // analog pin 4 is hardware I2C SDA (data pin) // analog pin 5 is hardware I2C SCL (clock pin) // The master (arduino) sends two bytes to write to LM4970 // byte 1 = address 111101x0 bit1 is determined by a resistor on the ADR pin // byte 2 = data byte 2 holds register and configuration information // Note: The address that we write to the Wire.beginTransmisson function call // is the same as above and in the datasheet, only shifted right once. // the Wire library is expecting the 7 MSB's and will clear or set LSB for Write/Read #include // this library makes I2C possible int i = 0; byte address = B01111011; //depends on how the ADR pin is wired 0x7B = pullup, 0x7A = pulldown byte mode = B00000000; // enable the device in normal operation byte freq = B01010001; // set the PWM frequency to 60Hz, HighPass cutoff to 6.3KHz byte amp = B10101010; // set the LED current drivers to 1.33X (also available: 1X, .66X, 2X) byte gain = B11010010; // set Midband Gain to medium, Input Signal Gain to 0dB byte pattern[9] = { // NOTE AN ERROR IN THE DATASHEET! BIT 7 OF PATTERN REGISTER SHOULD BE '0' B01100000, //disable I2C, enable audio sync B01100001, //enable I2C, disable audio sync B01100011, //enable L1 B01100101, //enable L2 B01101001, //enable L2 B01100111, //enable L1,L2 B01101101, //enable L2,L3 B01101011, //enable L1,L3 B01101111}; //enable L1,L2,L3 byte current = B10000000; // bit 0-5 conrtrol LED ouput current. see datasheet Table 6 void setup(){ Serial.begin(9600); Wire.begin(); //arduino is I2C master, analog4 = SDA, analog5 = SCL delay(100); Wire.beginTransmission(address); //send LM4970 address Wire.send(mode); //set the mode Wire.endTransmission(); delay(100); Wire.beginTransmission(address); Wire.send(freq); //set the PWM frequency Wire.endTransmission(); }// end setup void loop(){ for (i=0; i<9; i++){ //scroll through the color combinations with Pattern Select Register Wire.beginTransmission(address); Wire.send(pattern[i]); Wire.endTransmission(); delay(1000); Serial.print(address,BIN); Serial.print('\t'); Serial.println(pattern[i],BIN); //Serial.print('\t'); } for (i=0; i<63; i++){ //scroll through the color combinations with Current Select Register Wire.beginTransmission(address); Wire.send(current); Wire.endTransmission(); current +=1; delay(100); Serial.print(address,BIN); Serial.print('\t'); Serial.println(current,BIN); } current = B10000000; //reset current byte for next time }// end loop