I have received Arduino Yun, Arduino Uno and Infineon RGB LED control shield...
I have used REST api style communication link between my android cell and arduino yun... I have merged bridge example of arduino yun and Infineon RGB LED Shield example for this prototype...
I am using processing for Android and PC application...
My processing sketch works fine with Android as well as widows/linux PC...
In my processing app.. two modes are there,
1. fix (fix color)
2. loop (rotate color)
Here is my processing sketch....
float r_color=127,g_color=127,b_color=127, rot_color;
float r_bar = width/2,g_bar = width/2,b_bar = width/2, rot_bar = width/2;
float r_yun, g_yun, b_yun, rot_yun = 200;
float rot_status = 0;
float fix_status = 1;
color backgroundcolor = color(50, 50, 0);
String url = "http://192.168.43.27/arduino/";
void setup()
{
orientation(LANDSCAPE);
textSize(34);
}
void draw()
{
background(backgroundcolor);
drawUI();
// text("IP = "+ip,20,130);
//text(url+str((int)r_yun),20,170);
}
void mousePressed()
{
// int mouse = (int)mouseX;
if (mouseY > height/6 && mouseY < height/6+60)
{
if( mouseX > width/3 && mouseX < width/3 + width/6)
{
rot_status = 1;
fix_status = 0;
String json[] = loadStrings(url + "rot/1/" +str((int)rot_yun));
println(url + "set/1/" + str((int)rot_yun));
delay(300);
}
if( mouseX > width/3 + width/6 && mouseX < 2*width/3)
{
rot_status = 0;
fix_status = 1;
String json[] = loadStrings(url + "set/1/" + str((int)r_yun));
println(url + "set/1/" + str((int)r_yun));
delay(300);
String json1[] = loadStrings(url + "set/2/" + str((int)g_yun));
println(url + "set/2/" + str((int)g_yun));
delay(300);
String json2[] = loadStrings(url + "set/3/" + str((int)b_yun));
println(url + "set/3/" + str((int)b_yun));
delay(300);
}
}
if( mouseX > 50 && mouseX < width-50)
{
if (mouseY > 2*height/6 && mouseY < 2*height/6+60 && rot_status == 1)
{
rot_color = map(mouseX, 50, width-50, 0, 255);
rot_yun = map(mouseX, 50, width-50, 0, 4090);
rot_bar = mouseX-50;
String json[] = loadStrings(url + "rot/1/" + str((int)rot_yun));
println(url + "rot/1/" + str((int)rot_yun));
}
else if (mouseY > 3*height/6 && mouseY < 3*height/6+60 && fix_status == 1)
{
r_color = map(mouseX, 50, width-50, 0, 255);
r_yun = map(mouseX, 50, width-50, 0, 4090);
r_bar = mouseX-50;
String json[] = loadStrings(url + "set/1/" + str((int)r_yun));
println(url + "set/1/" + str((int)r_yun));
}
else if (mouseY > 4*height/6 && mouseY < 4*height/6+60 && fix_status == 1)
{
g_color = map(mouseX, 50, width-50, 0, 255);
g_yun = map(mouseX, 50, width-50, 0, 4090);
g_bar = mouseX-50;
String json[] = loadStrings(url + "set/2/" + str((int)g_yun));
println(url + "set/3/" + str((int)g_yun));
}
else if (mouseY > 5*height/6 && mouseY < 5*height/6+60 && fix_status == 1)
{
b_color = map(mouseX, 50, width-50, 0, 255);
b_yun = map(mouseX, 50, width-50, 0, 4090);
b_bar = mouseX-50;
String json[] = loadStrings(url + "set/3/" + str((int)b_yun));
println(url + "set/3/" + str((int)b_yun));
}
}
}
void drawUI()
{
pushStyle();
textAlign(CENTER);
stroke(255);
//fill(color(r_color,g_color,b_color));
//rect(width/3, 1*height/6, width/3, 60);
fill(rot_status * 200);
rect(width/3, 1*height/6, width/6, 60);
fill(fix_status * 200);
rect(width/3 + width/6, 1*height/6, width/6, 60);
if(rot_status == 1)
{
fill(color(100,200,200));
rect(50, 2*height/6, width-100, 60);
fill(color(50,100,100));
rect(50, 2*height/6, rot_bar, 60);
fill(0);
text("SPEED", width/2, 2*height/6+43);
}
if(fix_status == 1)
{
fill(color(r_color,g_color,b_color));
rect(width/3, 2*height/6, width/3, 60);
fill(color(255,0,0));
rect(50, 3*height/6, width-100, 60);
fill(color(0,255,0));
rect(50, 4*height/6, width-100, 60);
fill(color(0,0,255));
rect(50, 5*height/6, width-100, 60);
fill(color(r_color,0,0));
rect(50, 3*height/6, r_bar, 60);
fill(color(0,g_color,0));
rect(50, 4*height/6, g_bar, 60);
fill(color(0,0,b_color));
rect(50, 5*height/6, b_bar, 60);
fill(color(255-r_color,255-g_color,255-b_color));
text("COLOR", width/2, 2*height/6+43);
}
fill(255);
text("IoT Holiday Lights", width/2, 60 );
fill(0);
text("LOOP", width/3 + width/12, height/6+43);
fill(0);
text("FIX", width/3 + width/6 + width/12 , height/6+43);
popStyle();
}
Here is my arduino yun sketch... Still clean up of code is not done.... Sorry for that...
/*
Arduino Yún Bridge example
This example for the Arduino Yún shows how to use the
Bridge library to access the digital and analog pins
on the board through REST calls. It demonstrates how
you can create your own API when using REST style
calls through the browser.
Possible commands created in this shetch:
* "/arduino/digital/13" -> digitalRead(13)
* "/arduino/digital/13/1" -> digitalWrite(13, HIGH)
* "/arduino/analog/2/123" -> analogWrite(2, 123)
* "/arduino/analog/2" -> analogRead(2)
* "/arduino/mode/13/input" -> pinMode(13, INPUT)
* "/arduino/mode/13/output" -> pinMode(13, OUTPUT)
This example code is part of the public domain
http://arduino.cc/en/Tutorial/Bridge
*/
#include <Bridge.h>
#include <YunServer.h>
#include <YunClient.h>
#define ADDRESS 0x15EUL
#define INTENSITY_RED 0x11U
#define INTENSITY_GREEN 0x12U
#define INTENSITY_BLUE 0x13U
#define INTENSITY_RGB 0x14U
#define CURRENT_RED 0x21U
#define CURRENT_GREEN 0x22U
#define CURRENT_BLUE 0x23U
#define CURRENT_RGB 0x24U
#define DMXOFF 0x30U
#define DMXON 0x31U
#define DMXSLOT 0x32U
#define DMX8BIT 0x33U
#define DMX16BIT 0x34U
#define OFFTIME_RED 0x41U
#define OFFTIME_GREEN 0x42U
#define OFFTIME_BLUE 0x43U
#define WALKTIME 0x50U
#define DIMMINGLEVEL 0x60U
#define FADERATE 0x61U
#define _CHANGE_ADDRESS 0x70U
#define READ_INTENSITY_RED 0x81U
#define READ_INTENSITY_GREEN 0x82U
#define READ_INTENSITY_BLUE 0x83U
#define READ_CURRENT_RED 0x84U
#define READ_CURRENT_GREEN 0x85U
#define READ_CURRENT_BLUE 0x86U
#define READ_OFFTIME_RED 0x87U
#define READ_OFFTIME_GREEN 0x88U
#define READ_OFFTIME_BLUE 0x89U
#define READ_WALKTIME 0x8AU
#define READ_DIMMINGLEVEL 0x8BU
#define READ_FADERATE 0x8CU
#define DIRECTACCESS_READ 0x90U // read twice
#define DIRECTACCESS_MOVE 0x91U
#define DIRECTACCESS_AND 0x92U
#define DIRECTACCESS_OR 0x93U
#define SAVEPARAMETERS 0xA0U
#define BCCUMODID 0x50030008U
#define CHIPID 0x40010004U
#define REDINTS 0x500300A0U // BCCU_CH5
#define REDINT 0x500300A4U
#define BLUEINTS 0x50030078U
#define STARTWALK 0x50030018U
#include <Wire.h>
unsigned int c[2] = {0};
unsigned int d[4] = {0};
unsigned int on = 0;
unsigned int message = 0;
unsigned long redcurr = 0;
unsigned long greencurr = 0;
unsigned long bluecurr = 0;
unsigned long redoff = 0;
unsigned long greenoff = 0;
unsigned long blueoff = 0;
unsigned long redint = 0x00;
unsigned long greenint = 0x00;
unsigned long blueint = 0x00;
unsigned long fadetime = 0x00;
unsigned long walk = 0x00;
unsigned long brightness = 1;
unsigned int r_send = 2048;
unsigned int g_send = 2048;
unsigned int b_send = 2048;
unsigned int rot = 0, rot_delay = 500;
// Listen on default port 5555, the webserver on the Yún
// will forward there all the HTTP requests for us.
YunServer server;
void setup() {
Serial.begin(9600);
Wire.begin();
Shield_init();
I2CWRITE2BYTES (ADDRESS, INTENSITY_RED, r_send); // RED
I2CWRITE2BYTES (ADDRESS, INTENSITY_GREEN, g_send); // GREEN
I2CWRITE2BYTES (ADDRESS, INTENSITY_BLUE, b_send); // BLUE
// Bridge startup
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
Bridge.begin();
digitalWrite(13, HIGH);
// Listen for incoming connection only from localhost
// (no one from the external network could connect)
server.listenOnLocalhost();
server.begin();
}
void loop() {
// Get clients coming from server
YunClient client = server.accept();
// There is a new client?
if (client) {
// Process request
process(client);
// Close connection and free resources.
client.stop();
}
if(rot==1){led_rotate();}
delay(20); // Poll every 20ms
}
void process(YunClient client) {
// read the command
String command = client.readStringUntil('/');
// is "digital" command?
if (command == "set") {
setCommand(client);
}
// is "analog" command?
if (command == "rot") {
rotCommand(client);
}
// is "mode" command?
if (command == "mode") {
modeCommand(client);
}
}
void setCommand(YunClient client) {
int set_clr,value;
// Read color number
set_clr = client.parseInt();
// Read intensity
if (client.read() == '/') {
value = client.parseInt();
}
client.print(F("color="));
client.print(set_clr);
if(set_clr == 1){r_send = value;}
else if(set_clr == 2){g_send = value;}
else if(set_clr == 3){b_send = value;}
rot = 0;
I2CWRITE2BYTES (ADDRESS, WALKTIME, 48);
I2CWRITE2BYTES (ADDRESS, INTENSITY_RED, r_send); // RED
I2CWRITE2BYTES (ADDRESS, INTENSITY_GREEN, g_send); // GREEN
I2CWRITE2BYTES (ADDRESS, INTENSITY_BLUE, b_send); // BLUE
// Send feedback to client
}
void rotCommand(YunClient client) {
int value;
// Read pin number
rot = client.parseInt();
if (client.read() == '/') {
value = client.parseInt();
}
I2CWRITE2BYTES (ADDRESS, WALKTIME, value/14);
rot_delay = value;
// Send feedback to client
client.print("rotation = ");
client.print(rot);
}
void modeCommand(YunClient client) {
int pin;
// Read pin number
pin = client.parseInt();
// If the next character is not a '/' we have a malformed URL
if (client.read() != '/') {
client.println(F("error"));
return;
}
String mode = client.readStringUntil('\r');
if (mode == "input") {
pinMode(pin, INPUT);
// Send feedback to client
client.print(F("Pin D"));
client.print(pin);
client.print(F(" configured as INPUT!"));
return;
}
if (mode == "output") {
pinMode(pin, OUTPUT);
// Send feedback to client
client.print(F("Pin D"));
client.print(pin);
client.print(F(" configured as OUTPUT!"));
return;
}
client.print(F("error: invalid mode "));
client.print(mode);
}
void I2CWRITE2BYTES (int Address, int Command, unsigned int Data)
{
unsigned int upperByte, lowerByte; // Separate 4 byte data into 2 byte values
lowerByte = Data;
upperByte = Data >> 8;
unsigned int lowerSLAD = (unsigned int) (Address & 0x00FF); // Putting address into correct format
unsigned int upperSLAD = Address >> 8;
upperSLAD |= 0x79; // First 5 bits 11110 and last bit '1' for a write
Wire.beginTransmission(byte(upperSLAD)); // Start I2C transmission
Wire.write(byte(lowerSLAD)); // address lower 8 bits of i2c address
Wire.write(byte(Command)); // write command
Wire.write(byte(upperByte)); // write data
Wire.write(byte(lowerByte));
Wire.endTransmission(true);
}
/*
Parameters (IN): int Address - Address of RGB LED Shield, Default 0x15E
int Command - Defined I2C Commands i.e. INTENSITY_RGB, CURRENT_RGB
unsigned int DataOne, unsigned int DataTwo, unsigned int DataThree - Three 16bit data to be written to slave
Parameters (OUT): None
Return Value: None
Description: This function will write 6 bytes of word to the I2C bus line
*/
void I2CWRITE6BYTES (unsigned int Address, unsigned int Command, unsigned int DataOne, unsigned int DataTwo, unsigned int DataThree) // DataOne: Red, DataTwo: Green, DataThree: Blue
{
unsigned int upperByte, lowerByte; // Split each Data parameter into upper and lower 8 bytes because I2C format sends 8 bytes of data each time
lowerByte = DataOne;
upperByte = DataOne >> 8;
unsigned int lowerSLAD = (unsigned int) (Address & 0x00FF);
unsigned int upperSLAD = Address >> 8;
upperSLAD |= 0x79; // First 5 bits 11110 and last bit '1' for a write
Wire.beginTransmission(byte(upperSLAD)); // Red
Wire.write(byte(lowerSLAD));
Wire.write(byte(Command));
Wire.write(byte(upperByte));
Wire.write(byte(lowerByte));
lowerByte = DataTwo;
upperByte = DataTwo >> 8;
Wire.write(byte(upperByte));
Wire.write(byte(lowerByte));
lowerByte = DataThree;
upperByte = DataThree >> 8;
Wire.write(byte(upperByte));
Wire.write(byte(lowerByte));
Wire.endTransmission(true);
}
/*
Parameters (IN): int Address - Address of RGB LED Shield, Default 0x15E
int Command - Defined I2C Commands i.e. DMX16Bit
unsigned int DataOne, unsigned int DataTwo, unsigned int DataThree, usigned int DataFour, unsigned int DataFive - Three 16bit data to be written to slave
Parameters (OUT): None
Return Value: None
Description: This function will write 12 bytes of word to the I2C bus line
*/
void I2CWRITE12BYTES (unsigned int Address, unsigned int Command, unsigned int DataOne, unsigned int DataTwo, unsigned int DataThree, unsigned int DataFour, unsigned int DataFive, unsigned int DataSix) // DataOne: Red, DataTwo: Green, DataThree: Blue
{
unsigned int upperByte, lowerByte;
lowerByte = DataOne;
upperByte = DataOne >> 8;
unsigned int lowerSLAD = (unsigned int) (Address & 0x00FF);
unsigned int upperSLAD = Address >> 8;
upperSLAD |= 0x79; // First 5 bits 11110 and last bit '1' for a write
Wire.beginTransmission(byte(upperSLAD));
Wire.write(byte(lowerSLAD));
Wire.write(byte(Command)); // write command
Wire.write(byte(upperByte)); // write 2 bytes
Wire.write(byte(lowerByte));
lowerByte = DataTwo;
upperByte = DataTwo >> 8;
Wire.write(byte(upperByte)); // write next two bytes
Wire.write(byte(lowerByte));
lowerByte = DataThree;
upperByte = DataThree >> 8;
Wire.write(byte(upperByte));
Wire.write(byte(lowerByte));
lowerByte = DataFour;
upperByte = DataFour >> 8;
Wire.write(byte(upperByte));
Wire.write(byte(lowerByte));
lowerByte = DataFive;
upperByte = DataFive >> 8;
Wire.write(byte(upperByte));
Wire.write(byte(lowerByte));
lowerByte = DataSix;
upperByte = DataSix >> 8;
Wire.write(byte(upperByte));
Wire.write(byte(lowerByte));
Wire.endTransmission(true);
}
/*
Parameters (IN): int Address - Address of RGB LED Shield, Default 0x15E
int Command - Defined read I2C Commands i.e. READ_INTENSITY_RED, READ_INTENSITY_GREEN, READ_INTENSITY_BLUE
Parameters (OUT): None
Return Value: Requested data from Shield will be sent back
Description: This function will request 2 bytes of word from the shield
*/
unsigned int I2CREAD (unsigned int Address, unsigned int Command) // Returns data sent by slave
{
int i = 0;
unsigned int lowerSLAD = (unsigned int) (Address & 0x00FF);
unsigned int upperSLAD = Address >> 8;
upperSLAD |= 0x79;
Wire.beginTransmission(byte(upperSLAD)); // Red
Wire.write(byte(lowerSLAD));
Wire.write(byte(Command));
Wire.endTransmission(false); // false for Repeated Start
Wire.beginTransmission(byte(upperSLAD));
Wire.write(byte(lowerSLAD));
Wire.requestFrom(upperSLAD, 2, true);
unsigned int data = 0;
while(Wire.available()) // slave may send less than requested. Print out received data byte
{
message = 1;
c[i] = Wire.read(); // receive a byte as character
i++;
}
Wire.endTransmission(true);
data = c[1]; // write data to serial monitor. c[1] is higher byte
data = (data << 8) | c[0]; // shift left and combine with lower byte
Serial.print("0x");
if (data < 0x1000)
Serial.print("0");
Serial.println(data, HEX);
return data;
}
/*
Parameters (IN): int Address - Address of RGB LED Shield, Default 0x15E
int Command - DIRECTACCESS_READ
Parameters (OUT): None
Return Value: Requested data from the Shield will be returned
Description: This function will request 4 bytes of data from shield.
*/
unsigned long I2CREAD_DIRECTACCESS (unsigned int Address, unsigned int Command, unsigned long registerAddress)
{
int i = 0;
unsigned int lowerSLAD = (unsigned int) (Address & 0x00FF); // sending command + address
unsigned int upperSLAD = Address >> 8;
upperSLAD |= 0x79; // First 5 bits 11110 and last bit '1' for a write
Wire.beginTransmission(byte(upperSLAD));
Wire.write(byte(lowerSLAD));
Wire.write(byte(Command));
unsigned int firstByte, secondByte, thirdByte, fourthByte;
firstByte = registerAddress >> 24; // top byte
secondByte = registerAddress >> 16;
thirdByte = registerAddress >> 8;
fourthByte = registerAddress; // bottom byte
Wire.write(byte(firstByte));
Wire.write(byte(secondByte));
Wire.write(byte(thirdByte));
Wire.write(byte(fourthByte));
Wire.endTransmission(false); // false for Repeated Start
Wire.beginTransmission(byte(upperSLAD)); // request for read
Wire.write(byte(lowerSLAD));
Wire.requestFrom(upperSLAD, 4, true);
unsigned long data = 0;
while(Wire.available()) // slave may send less than requested. Print out received data byte
{
d[i] = 0;
d[i] = Wire.read(); // receive a byte as character
i++;
}
Wire.endTransmission(true);
data = d[3]; // combining into one variable. Highest byte received first
data = (data << 8) | d[2];
data = (data << 8) | d[1];
data = (data << 8) | d[0];
Serial.print("0x");
if (data < 0x10000000)
Serial.print("0");
Serial.println(data, HEX);
return data;
}
/*
Parameters (IN): int Address - Address of RGB LED Shield, Default 0x15E
int Command - Defined I2C Commands i.e. DIRECTACCESS_OR, DIRECTACCESS_AND, DIRECTACCESS_MOVE
unsigned long registerAddress - address of target register
unsigned long Data - 32 bits data to be written to register
Parameters (OUT): None
Return Value: None
Description: This function will write 4 bytes of data to specified register
*/
void I2CWRITE_DIRECTACCESS (unsigned int Address, unsigned int Command, unsigned long registerAddress, unsigned long Data) // For accessing registers directly
{
int i = 0;
unsigned int lowerSLAD = (unsigned int) (Address & 0x00FF); // sending command + address
unsigned int upperSLAD = Address >> 8;
upperSLAD |= 0x79; // First 5 bits 11110 and last bit '1' for a write
Wire.beginTransmission(byte(upperSLAD));
Wire.write(byte(lowerSLAD));
Wire.write(byte(Command));
unsigned int firstByte, secondByte, thirdByte, fourthByte; // Send address of register first
firstByte = registerAddress >> 24; // top byte
secondByte = registerAddress >> 16;
thirdByte = registerAddress >> 8;
fourthByte = registerAddress; // bottom byte
Wire.write(byte(firstByte));
Wire.write(byte(secondByte));
Wire.write(byte(thirdByte));
Wire.write(byte(fourthByte));
firstByte = Data >> 24; // top byte
secondByte = Data >> 16;
thirdByte = Data >> 8;
fourthByte = Data; // bottom byte
Wire.write(byte(firstByte)); // send 4 bytes of data
Wire.write(byte(secondByte));
Wire.write(byte(thirdByte));
Wire.write(byte(fourthByte));
Wire.endTransmission(true);
}
/*
Parameters (IN): int Address - Address of RGB LED Shield, Default 0x15E
unsigned int newAddress - Address the shield should change to
Parameters (OUT): None
Return Value: None
Description: This function will change the I2C address of the slave
*/
void CHANGEADDRESS (unsigned int Address, unsigned int newAddress)
{
unsigned int lowerSLAD = (unsigned int) (Address & 0x00FF);
unsigned int upperSLAD = Address >> 8;
upperSLAD |= 0x79; // First 5 bits 11110 and last bit '1' for a write
Wire.beginTransmission(byte(upperSLAD)); // Red
Wire.write(byte(lowerSLAD));
Wire.write(byte(0x70)); // Command to change address
lowerSLAD = (unsigned int) (newAddress & 0x00FF);
upperSLAD = newAddress >> 7; // Split address into 2 bytes
upperSLAD |= 0xF0; // 10 bit addressing: First 5 bits have to be 11110.
upperSLAD &= 0xFE;
Wire.write(byte(upperSLAD));
Wire.write(byte(lowerSLAD));
Wire.endTransmission(true);
}
/*
Parameters (IN): int Address - Address of RGB LED Shield, Default 0x15E
unsigned int Command - DMXON, DMXOFF
Parameters (OUT): None
Return Value: None
Description: This function will enable or disable DMX512 control on shield
*/
void I2CDMX (unsigned int Address, unsigned int Command) // Switch off / on the DMX
{
unsigned int lowerSLAD = (unsigned int) (Address & 0x00FF); // Putting address into correct format
unsigned int upperSLAD = Address >> 8;
upperSLAD |= 0x79;
Wire.beginTransmission(byte(upperSLAD)); // Start I2C transmission
Wire.write(byte(lowerSLAD));
Wire.write(byte(Command));
Wire.endTransmission(true);
}
/*
Parameters (IN): int Address - Address of RGB LED Shield, Default 0x15E
Parameters (OUT): None
Return Value: None
Description: This function will request the shield to save configurations to flash memory
*/
void I2CSAVEPARAM (unsigned int Address)
{
int i = 0;
unsigned int lowerSLAD = (unsigned int) (Address & 0x00FF);
unsigned int upperSLAD = Address >> 8;
upperSLAD |= 0x79;
Wire.beginTransmission(byte(upperSLAD));
Wire.write(byte(lowerSLAD));
Wire.write(byte(SAVEPARAMETERS)); // write SAVEPARAMETERS command
Wire.endTransmission(false); // false for Repeated Start
Wire.beginTransmission(byte(upperSLAD));
Wire.write(byte(lowerSLAD)); // write to address lower 8 bits of slave address
Wire.requestFrom(upperSLAD, 2, true); // send READ request with upper slave address
unsigned int data = 0;
while(Wire.available()) // slave may send less than requested. Print out received data byte
{
message = 1;
c[i] = Wire.read(); // receive a byte as character
i++;
}
Wire.endTransmission(true); // STOP condition
data = c[1]; // print the data on serial monitor
data = (data << 8) | c[0];
Serial.print("0x");
if (data < 0x1000)
Serial.print("0");
Serial.println(data, HEX);
}
void Shield_init()
{
//while(!Serial);
while (on != 1) // Wait for shield to respond
{
I2CDMX (ADDRESS, DMXOFF); // disable DMX
I2CWRITE2BYTES (ADDRESS, FADERATE, 0x0000); // Immediate fade
I2CWRITE2BYTES (ADDRESS, DIMMINGLEVEL, 0x0000); // 0% brightness level
on = I2CREAD(ADDRESS, READ_DIMMINGLEVEL); // Request for brightness level
if (message == 1 && on == 0) // If message received and brightness level = 9%
{
message = 0;
on = 1; // break out of loop
}
}
while (redcurr != 0x15 || greencurr != 0x15 || bluecurr != 0x15 || redoff != 0x38 || greenoff != 0x39 || blueoff != 0x38 || brightness != 0)
{
I2CWRITE6BYTES (ADDRESS, INTENSITY_RGB, 0x0000, 0x000, 0x0000); // Off Light
// Ensure that parameters are set up correctly. Read back and check. If wrong, write and read again.
redcurr = I2CREAD (ADDRESS, READ_CURRENT_RED); // Read the red current intensity
greencurr = I2CREAD (ADDRESS, READ_CURRENT_GREEN); // Read the green current intensity
bluecurr = I2CREAD (ADDRESS, READ_CURRENT_BLUE); // Read the blue current intensity
redoff = I2CREAD (ADDRESS, READ_OFFTIME_RED); // Read the off-time of the red channel
greenoff = I2CREAD (ADDRESS, READ_OFFTIME_GREEN); // Read the off-time of the green channel
blueoff = I2CREAD (ADDRESS, READ_OFFTIME_BLUE); // Read the off-time of the blue channel
brightness = I2CREAD (ADDRESS, READ_DIMMINGLEVEL); // Read the dimming level
I2CWRITE2BYTES (ADDRESS, OFFTIME_RED, 0x38); // Set off-time of red channel to 0x38
I2CWRITE2BYTES (ADDRESS, OFFTIME_GREEN, 0x39); // Set off-time of green channel to 0x39
I2CWRITE2BYTES (ADDRESS, OFFTIME_BLUE, 0x38); // Set off-time of blue channel to 0x38
I2CWRITE2BYTES (ADDRESS, CURRENT_RED, 0x15); // Set current intensity of red channel to 0x15
I2CWRITE2BYTES (ADDRESS, CURRENT_GREEN, 0x15); // Set current intensity of green channel to 0x15
I2CWRITE2BYTES (ADDRESS, CURRENT_BLUE, 0x15); // Set current intensity of blue channel to 0x15
I2CWRITE2BYTES (ADDRESS, DIMMINGLEVEL, 0x0000);
}
delay(100);
I2CWRITE2BYTES (ADDRESS, FADERATE, 0x0014); // Fade Rate --> 0.7s
I2CWRITE2BYTES (ADDRESS, WALKTIME, 0x000F);
I2CWRITE6BYTES (ADDRESS, INTENSITY_RGB, 0x0555, 0x0555, 0x0555); // White Light
I2CWRITE2BYTES (ADDRESS, DIMMINGLEVEL, 0x0FFF); // Maximum Brightness
delay(2000); // wait 2 sec
// change lamp colour to red
I2CWRITE2BYTES (ADDRESS, INTENSITY_RED, 0x0FFF); // change red colour intensity to 0xFFF
I2CWRITE2BYTES (ADDRESS, INTENSITY_GREEN, 0x0000); // change green colour intensity to 0x000
I2CWRITE2BYTES (ADDRESS, INTENSITY_BLUE, 0x0000); // change blue colour intensity to 0x000
delay(1000);
I2CWRITE2BYTES (ADDRESS, INTENSITY_RED, 0x0000);
I2CWRITE2BYTES (ADDRESS, INTENSITY_GREEN, 0x0FFF);
delay(1000);
I2CWRITE2BYTES (ADDRESS, INTENSITY_GREEN, 0x0000);
I2CWRITE2BYTES (ADDRESS, INTENSITY_BLUE, 0x0FFF);
delay(1000); // Read back values from slave
I2CWRITE2BYTES (ADDRESS, WALKTIME, 24); // set walk-time 240ms
}
void led_rotate()
{
I2CWRITE2BYTES (ADDRESS, INTENSITY_RED, 0x0fff); // RED
I2CWRITE2BYTES (ADDRESS, INTENSITY_GREEN, 0x0000); // GREEN
I2CWRITE2BYTES (ADDRESS, INTENSITY_BLUE, 0x0000); // BLUE
delay(rot_delay);
I2CWRITE2BYTES (ADDRESS, INTENSITY_RED, 0x0000); // RED
I2CWRITE2BYTES (ADDRESS, INTENSITY_GREEN, 0x0fff); // GREEN
I2CWRITE2BYTES (ADDRESS, INTENSITY_BLUE, 0x0000); // BLUE
delay(rot_delay);
I2CWRITE2BYTES (ADDRESS, INTENSITY_RED, 0x0000); // RED
I2CWRITE2BYTES (ADDRESS, INTENSITY_GREEN, 0x0000); // GREEN
I2CWRITE2BYTES (ADDRESS, INTENSITY_BLUE, 0x0fff); // BLUE
delay(rot_delay);
}
Here is video of this prototype....
my 12V DC supply for LED strip is only capable of delivering 300mA so I have connected only few LEDs... I am finding some powerful 12V DC supply to drive 2amp load of 5m LED strip...
This is just initial prototype ... I will be modifying hardware and software to make it extremely user friendly...
Thanks..
Madhuri
Top Comments