Good day all, I am working on a big project with several arduino nano's tied together with I2c.
(and so far it seems to be going well given enough time, but I am still a beginner)
This is the project: I have 1 arduino running as a master on a I2c network, by using buttons it will send the number 1,2,3 etc on the network to the other arduinos. (and showing the function on a display)
Some arduino's will transfer the number to a motor, relais or waveshield or to a LPD8806 led strip.
Now I have got the LPD8806 part to work with the I2C, by sending 1,2 or 3 to this arduino it will execute the light pattern associated with it.
But Iam having trouble keeping the pattern in a loop, it will now run for 1 or 2 times and then I have to send the number again. And the pattern cannot be interrupted.
The funny thing is that the hole LPD8806 script came from a wheelchare project by Cranium.
(many thanks go to him, I've got another LPD8806 project running completly on his script)
Original script: http://arduino.cc/forum/index.php/topic,79839.15.html
The orginal script is using a button who can interrupted the current running loop at all times, but I am not sure how to replace the button control with the I2c control and keep the hole thing running the same.
I will be grateful for any tips or help...
Here is the changed script up till now: (orginal can be found on the link above)
#include "LPD8806.h"
#include "SPI.h"
#include <Wire.h>
#define LED_OUT 13
#define ADDRESS 42
#define button 3
#define stripSize 64
int butPush = 0;
int currentMode = 9;
int numModes = 12;
// on Arduino 168/328 thats data = 11, and clock = pin 13
//LPD8806 strip = LPD8806(stripSize);
// Choose which 2 pins you will use for output.
// Can be any valid output pins.
int dataPin = 5;
int clockPin = 8;
// Set the first variable to the NUMBER of pixels. 32 = 32 pixels in a row
// The LED strips are 32 LEDs per meter but you can extend/cut the strip
LPD8806 strip = LPD8806(10, dataPin, clockPin);
void setup() {
// Start up the LED strip
strip.begin();
// Update the strip, to start they are all 'off'
strip.show();
// Serial.begin(9600);
pinMode(button,INPUT);
pinMode(LED_OUT, OUTPUT);
Serial.begin(9600);
Wire.begin(ADDRESS);
Wire.onReceive(receiveEvent);
}
int micLevel;
int colorLevel;
int numLeds;
int cmd;
void loop() {
}
void receiveEvent(int howMany){
while (Wire.available() > 0){
char cmd = Wire.read();
if (cmd == 0){ // Meaning we need to return the light value from the light sensor
}
Serial.println();
Serial.println();
if(cmd == 1){ // Meaning we need to return the light value from the light sensor
rainbow(25);
break;
}
Serial.println();
if(cmd == 2){ // Meaning we need to return the light value from the light sensor
rainbowCycle(0); // make it go through the cycle fairly fast
break;
}
Serial.println();
if(cmd == 3){ // Meaning we need to return the light value from the light sensor
// fill the entire strip with...
colorWipe(strip.Color(127,0,0), 40); // red
colorWipe(strip.Color(0, 127,0), 40); // green
colorWipe(strip.Color(0,0,127), 40); // blue
break;
}
Serial.println();
if(cmd == 4){ // Meaning we need to return the light value from the light sensor
}
Serial.println();
if(cmd == 5){ // Meaning we need to return the light value from the light sensor
}
Serial.println();
if(cmd == 6){ // Meaning we need to return the light value from the light sensor
}
Serial.println();
if(cmd == 7){ // Meaning we need to return the light value from the light sensor
}
Serial.println();
if(cmd == 8){ // Meaning we need to return the light value from the light sensor
}
Serial.println();
if(cmd == 9){ // Meaning we need to return the light value from the light sensor
}
Serial.println();
}
}
void modeSelect(){
switch (currentMode){
case 1:
music(0); //sound sensitive mode with variable LEDs lit
break;
case 2:
music(1); //sound sensitive mode with ALL LEDs lit
break;
case 3:
colorChase(strip.Color(127,0,0), 20); // full brightness red
colorChase(strip.Color(127,127,0), 20); // orange
colorChase(strip.Color(0,127,0), 20); // green
colorChase(strip.Color(0,127,127), 20); // teal
colorChase(strip.Color(0,0,127), 20); // blue
colorChase(strip.Color(127,0,127), 20); // violet
break;
case 4:
// fill the entire strip with...
colorWipe(strip.Color(127,0,0), 40); // red
colorWipe(strip.Color(0, 127,0), 40); // green
colorWipe(strip.Color(0,0,127), 40); // blue
break;
case 5:
rainbow(25);
break;
case 6:
rainbowCycle(0); // make it go through the cycle fairly fast
break;
case 7:
circlinglights(20); //flash yellow
break;
case 8:
ran(20); //random white lights
break;
case 9:
ran1(15); //this is actually the off mode...
break;
case 10:
shiftwhite(100); //Green with shifting yellow
break;
case 11:
kit(1);
break;
case 12:
xmas(300);
break;
}
}
void xmas(int dly){
int color=0;
while (butPush==0){
for (int i=0; i<stripSize; i++){
if (digitalRead(button)==1) {butPush=1; i=stripSize;}
if (color==4){
strip.setPixelColor(i,127,127,127); //white
}
else if (color==3){
strip.setPixelColor(i,127,90,0); //yellow
}
else if (color==2){
strip.setPixelColor(i,0,0,127); //blue
}
else if (color==1){
strip.setPixelColor(i,0,127,0); //green
}
else {
strip.setPixelColor(i,127,0,0); //red
}
if (color++==4) color=0;
}
if (butPush==0){
strip.show();
delay(dly);
}
}
}