This is my first manually typed code. I'm sure there may be some glaring "schoolboy errors" in it, so wondered if people could give it the 'once over' In particular, I have never used C++ arrays, storing binary data within, and then trying to read them bit by bit. In perl, much easier; you would simply use a multi-dimensional something like this:
@code1=('10101010', '01010101');
$bit=$code1[0][0] (..through to..) code1[0][7]
$bit=$code1[1][0] ... code1[1][7]
So this is my Arduino code. Welcome to suggestions.
int pinArray[]={2,3,4,5,6,7,8,9};
int code1[]={B10101010, B01010101,B10101010, B01010101,B10101010, B01010101};
int count=0;
int split=0; // Counter for the bit loop
int led; // Store bit data
byte x; // Used to store the binary data in code1
void setup(){
for (count=0; count<8; count++){
pinMode(pinArray[count],OUTPUT); // Sets pinMode as output on pinArray pins
]
}
void loop(){
for (count=0; count<6; count++){
x=code1[count];
ledDisplay(x);
}
}
void ledDisplay(){
for (split=7; split>=0; split--){
led=bitRead(x,split);
if (led == 1){
digitalWrite(split+2,HIGH);
}
else{
digitalWrite(split+2,LOW);
}
}
}
Have just modified split as realised bit7 is the leftmost digit. In split, I am adding 2 to the value. Does this need to be enclosed in brackets,ie (split+2) ?