To use some shift register, I need to give them a number in wich every bit means on/off in that output pin of the ICs. To do that, I wrote a program that should turn on the selected pins adding a 1 or a 0 to a char, and then convert int to the number I want:
void send(int column, int layer) {
// Creates the binary number to send from the given column and layer values
static char data[sizeof(columns) + sizeof(layers];
for (int i = 0; i < sizeof(data); i++) {
if (i == columns[column] or i == layers[layer]) {
strcat(data, "1");
} else {
strcat(data, "0");
}
}
/**** HELP ****/
// Sends the data
digitalWrite(LATCH_PIN, LOW); // Starts the transmission
shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, data); // Sends the data of the fourth IC
shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, data >> 8);
shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, data >> 16);
shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, data >> 24); // Sends the data of the first IC
digitalWrite(LATCH_PIN, HIGH); // Ends the transmission
}
In the part where is written HELP is the problem, because I don't know how to convert this char array to a number that can be read by the IC. I think I could someway convert the data array to a number, but would be a 30 digit number, and then I should rewrite it as another int in winch its binary form is the same than the decimal of the very large number before.
If I understand your question correctly, you want binary bit manipulation. For instance
unsigned int myBits = 0;
To set bit 0 use bitwise OR (single | operator)
myBits = myBits | 0x1;
To set any other bit, just use a bit (0x1) and shift it to the left before using OR to set the specific bit
myBits = myBits | ( 0x1 << 5 );
You can do this with multiple bits. You can delete bits with bitwise AND (& operator). All bits you do not want to delete need to be 0x1. Check out boolean logic.
Thank you! I'll search boolean logic and bit and byte functions, didn't know anything about that.
To everyone who want more information about my shift register, is a 74HC595n, an 8 bit shift register. The function shiftOut() sends a number. Each bit of the number represents a high (1) or low (0) voltage output of one of its pins, so I wanted a way to control this on/off in the number I send to animate the LED cube
I've built.