Hello, I am trying to control a Rainbowduino (a 64 rgb LED driver with an atmega328 and Arduino bootloader) from an Arduino Uno. The Rainbowduino has an 8x8 rgb led matrix and the frames are saved onto an SD card. However, when I run the program, only half of the data is transmitted from the SD card through the Arduino and to the Rainbowduino. The first 32 LEDs light up how they should, but the 33rd LED is blue and all the rest are white. I am unsure whether this is a hardware problem or a software problem. I am posting in this forum because I think it's the latter since half of the info is being transmitted properly (but just incase should I have anything connecting the Rainbowduino and Arduino? Right now I have just wires connecting everything).
Anyway, here is the gist of my master code (the Arduino):
#include <Wire.h>
#include <SD.h>
int frames;
byte r[64]; //these are assigned values from the SD card
byte b[64]; //I haven't included the code because I know
byte g[64]; //it is assigning the proper values.
//for example r[0]=020;
void setup(){
Wire.begin();
}
void loop(){
for(k=0;k<2;k++){ //Number of frames
Wire.beginTransmission(2);
for(int j=0;j<64;j++){
Wire.write(r[j]);
Wire.write(g[j]);
Wire.write(b[j]);
}
Wire.endTransmission();
long time=millis(); //delay between frames
while(millis()-time<300){}
}
}
And this is the code on the slave (Rainbowduino):
#include "Wire.h"
#include <Rainbowduino.h>
byte r[64],g[64],b[64];
void setup(){
Rb.init(); //initializes the Rainbowduino, not important
Wire.begin(2);
Wire.onReceive(expansionReceive);
}
void loop(){
}
void expansionReceive(int numBytes){
byte y=0;
for(int j=0;j<64;j++){
r[j]=Wire.read();
g[j]=Wire.read();
b[j]=Wire.read();
Rb.setPixelXY(0,y,r[j],g[j],b[j]);
y++; //y corresponds with spots on the matrix.
}
}
If you see anything wrong with this code please let me know! If it is a hardware problem such as needing a pullup resistor or something (not even totally sure what those are) let me know as well!
Because ultimately I'm going to add inputs and I don't want to miss a reading while the Arduino is essentially paused.
There is fundamentally no difference between your blocking function and the delay() function. You will miss readings using delay(). You will miss readings using your while loop.
You do not seem to understand the blink with delay example. It will do you a world of good to study the example until you DO understand it.
Not if I put a check for input changes inside the while loop. The whole point is delay pauses everything whereas the other way allows you to multitask. Maybe in this particular instance at this particular time I don't have anything inside that function but that doesn't mean I won't be adding something. But this is wholly irrelevant to my topic.
Sovereignty:
Not if I put a check for input changes inside the while loop. The whole point is delay pauses everything whereas the other way allows you to multitask. Maybe in this particular instance at this particular time I don't have anything inside that function but that doesn't mean I won't be adding something. But this is wholly irrelevant to my topic.
It may be irrelevant to your question, but the approach you're taking is IMO a very poor one which will lead to complex fragile code.
Learn to use a non-blocking approach following the techniques demonstrated in the blink without delay example sketch. This approach makes it easy to control multiple activities independently, both time-based and event-based. Changing to a non-blocking approach requires simple but sweeping changes to the structure of your code and the later you leave it to make that change the more work it will take. I recommend you bite the bullet now.