Hi, good to know. I've added to void setup();
// additional channels
// pin2=ch65, pin3=ch66, pin4=ch67, pin5=ch68, pin6=ch69, pin7=ch70
// pin8=ch71, pin9=ch72, pin10=ch73, pin11=ch74, pin12=ch75, pin13=ch76
for(read_loop = 2; read_loop < 14; read_loop++) {
pinMode(read_loop, OUTPUT);
}
and to void loop() ;
// additional channels
for(read_loop = 2; read_loop < 14; read_loop++) {
while (!Serial.available());
if (Serial.read() != 0)
digitalWrite(read_loop, HIGH);
else
digitalWrite(read_loop, LOW);
}
You now need to output 76 channels of data from Vixen. Full code:
#include <Wire.h>
unsigned int output_A;
unsigned int output_B;
unsigned int read_loop;
unsigned int IC_loop;
void setup() {
Serial.begin(115200);
Wire.begin();
for (IC_loop = 0; IC_loop < 4; IC_loop++) {
switch (IC_loop) {
case 0:
Wire.beginTransmission((byte)0x20);
break;
case 1:
Wire.beginTransmission((byte)0x21);
break;
case 2:
Wire.beginTransmission((byte)0x22);
break;
case 3:
Wire.beginTransmission((byte)0x23);
break;
}
Wire.write((byte)0x00);
Wire.write((byte)0x00);
Wire.write((byte)0x00);
Wire.endTransmission();
switch (IC_loop) {
case 0:
Wire.beginTransmission((byte)0x20);
break;
case 1:
Wire.beginTransmission((byte)0x21);
break;
case 2:
Wire.beginTransmission((byte)0x22);
break;
case 3:
Wire.beginTransmission((byte)0x23);
break;
}
Wire.write((byte)0x12);
Wire.write((byte)0x00);
Wire.write((byte)0x00);
Wire.endTransmission();
}
// additional channels
// pin2=ch65, pin3=ch66, pin4=ch67, pin5=ch68, pin6=ch69, pin7=ch70
// pin8=ch71, pin9=ch72, pin10=ch73, pin11=ch74, pin12=ch75, pin13=ch76
for(read_loop = 2; read_loop < 14; read_loop++) {
pinMode(read_loop, OUTPUT);
}
}
void loop() {
for (;;) {
while (!Serial.available());
if (Serial.read() != 'V') {
continue;
}
while (!Serial.available());
if (Serial.read() != 'I') {
continue;
}
while (!Serial.available());
if (Serial.read() != 'X') {
continue;
}
while (!Serial.available());
if (Serial.read() != 'E') {
continue;
}
while (!Serial.available());
if (Serial.read() != 'N') {
continue;
}
for (IC_loop = 0; IC_loop < 4; IC_loop++) {
output_A = 0;
for (read_loop = 0; read_loop < 8; read_loop++) {
while (!Serial.available());
if (Serial.read() != 0)
bitSet(output_A, read_loop);
}
output_B = 0;
for (read_loop = 0; read_loop < 8; read_loop++) {
while (!Serial.available());
if (Serial.read() != 0)
bitSet(output_B, read_loop);
}
switch (IC_loop) {
case 0:
Wire.beginTransmission((byte)0x20);
break;
case 1:
Wire.beginTransmission((byte)0x21);
break;
case 2:
Wire.beginTransmission((byte)0x22);
break;
case 3:
Wire.beginTransmission((byte)0x23);
break;
}
Wire.write((byte)0x12);
Wire.write((byte)output_A);
Wire.write((byte)output_B);
Wire.endTransmission();
}
// additional channels
for(read_loop = 2; read_loop < 14; read_loop++) {
while (!Serial.available());
if (Serial.read() != 0)
digitalWrite(read_loop, HIGH);
else
digitalWrite(read_loop, LOW);
}
}
}
To explain just this line, so the code is easier to read.
while (!Serial.available());
Basically means ‘pause here until a serial byte has arrived’.
How?
; = the line ends here.
{ = the line continues until }.
Nothing = the line includes the line below only.
As the line ends with ‘;’ that is the end of the ‘while’ statement.
The function of a ‘while’ statement is;
while loops will loop continuously, and infinitely, until the expression inside the parenthesis, () becomes false. Something must change the tested variable, or the while loop will never exit.
https://www.arduino.cc/en/Reference/While
While ever the statement is ‘true’ as it will get to the end of the line and then go back to the start of the line because of the ‘;’.
Great but what are we testing in the parenthesis?
!Serial.available()
Serial.available()
Get the number of bytes (characters) available for reading from the serial port. This is data that's already arrived and stored in the serial receive buffer (which holds 64 bytes).
https://www.arduino.cc/en/Serial/Available
If there are no bytes the result is 0 or ‘false’ and if there are bytes the result is a number or ‘true’.
There are two constants used to represent truth and falsity in the Arduino language: true, and false.
false
false is the easier of the two to define. false is defined as 0 (zero).
true
true is often said to be defined as 1, which is correct, but true has a wider definition. Any integer which is non-zero is true, in a Boolean sense. So -1, 2 and -200 are all defined as true, too, in a Boolean sense.
https://www.arduino.cc/en/Reference/Constants
and;
!
In my own terms as the link doesn’t explain this well:
It reverses the result. True becomes false and false becomes true.
https://www.arduino.cc/en/Reference/Boolean
To review:
We now have:
while (!Serial.available());
‘While’ = if whatever comes next is true, stay in loop, if not move on to the next bit of code.
‘!’ = whatever result comes next reverse it.
‘Serial.available()’ true if a serial byte is available, false if not.
‘ ; ‘ end of the loop.
Now we know what all the parts do we can see how we make them do what we want – a pause until a serial byte is available.
We setup a loop to keep looping until we get the result we want. This is ‘while()’ and then check something ‘Serial.available()’.
The problem is ‘while’ only keeps looping while the result is true, and we want it to loop UNTILL the result is true, so we have to improvise and add an ‘!’ to reverse the result.
I suspect that makes sense or is as clear as mud, but read over it a couple of times and it might make sense. If it doesn’t please let me know as I’m self-taught too and it’s hard to know when helping others, as to whether I’m patronising or above people’s heads.
Hi,
I tried the code and it seems to be working perfectly! Thank you so much. Later today I will run it for an extended amount of time just to ensure I am not missing anything. You don't know how much you actually helped me. Also thanks so much for the explanation. It makes complete sense and is definitely a great learning tool!
Thanks
It looks like they have some seconds they are selling off at $14.99. A cheap way to get 64 digital port outputs or $24.99 full price.
http://macetech.com/store/index.php?main_page=product_info&cPath=12&products_id=63
http://macetech.com/store/index.php?main_page=product_info&products_id=23
