I'm trying to extend an Arduino project using shift registers and I'm trying to build it on the already existing code. The existing project is the repatcher Repatcher | Open Music Labs. I'm troubled with some part of the code, as it sets some digital pins to output, but doesn't write any value to them. This is the part of the code that troubles me:
for (char i = 2; i <= 7; i++) { // get digital values
digitalWrite(i,LOW);
pinMode(i,OUTPUT);
delay(1);
byte patch = 0;
for (byte k = 8; k <= 13; k++) {
patch |= (digitalRead(k) << (k - 8));
}
patch = (patch ^ 0xff) & 0x3f;
pinMode(i,INPUT);
digitalWrite(i,HIGH);
buffer[j++] = patch;
}
The digitalWrite(i, LOW); at the beginning of the for loop is to turn the pullup resistors of the pins off (they've all been set to input in the setup function), and at the end of the loop it switches each pin to input and turns the resistors on again. But in the middle of the loop it switches pins 2-7 one by one to output, but it doesn't write anything to them. Can someone explain what happens if you don't specify a value to an output pin?
I guess its state will be low, but then, what kind of result will any operation give on a series of low pins?
Here's the whole code, if it is more helpful.
byte buffer[19]; // data transfer buffer
void setup() {
// set all digital pins to input with pullups on
for (byte i = 2; i <= 13; i++) {
pinMode(i,INPUT);
digitalWrite(i,HIGH);
}
// start serial port at 38400 bps:
Serial.begin(38400);
while (Serial.read() != 0xab); // wait for turn on signal
}
void loop() {
buffer[0] = 0xc0; // start character
byte j = 1;
for (char i = 5; i >= 0; i--) { // get analog values
unsigned int mod = analogRead(i);
buffer[j++] = mod & 0x007f;
buffer[j++] = (mod >> 7) & 0x0007;
}
for (char i = 2; i <= 7; i++) { // get digital values
digitalWrite(i,LOW);
pinMode(i,OUTPUT);
delay(1);
byte patch = 0;
for (byte k = 8; k <= 13; k++) {
patch |= (digitalRead(k) << (k - 8));
}
patch = (patch ^ 0xff) & 0x3f;
pinMode(i,INPUT);
digitalWrite(i,HIGH);
buffer[j++] = patch;
}
Serial.write(buffer, 19);
if (Serial.read() == 0xba) { // if turn off signal recieved
while (Serial.read() != 0xab); // idle till turn on recieved
}
}
The idea is to connect a pin of the first group (2-7) with one of the second group (8-13) with a wire and Arduino will create a byte which will then be translated in Pure Data to specify a connection between two modules. It's a modular interface for music.
Hope what I say and ask is pretty clear...
Thanks