hello : )
I have just set up a shift register circuit on a breadboard to control a 7 segment display. arduino pins : 8, 11 and 12 are in use only, and it works great. i use max msp to control the arduino, which sends 8 bit (0-255) numbers to the arduino which converts this to serial for the 595 shift registers.
The problem I am having, is that the sketch I am using appears to be created only to demonstrate the shift register concept, therefore all the other ins and outs on the arduino are not available.
i am wondering if it is possible to add code to the sketch (below), so that all the other pins can be used on the arduino ,as well as the 3 pins assigned for the shift registers via serial?
here is a link to the breadboard and arduino sketch
and here is a link to the max msp patch:
thanks for your help on this : )
here is the arduino sketch:
//Pin connected to ST_CP of 74HC595
int latchPin = 8;
//Pin connected to SH_CP of 74HC595
int clockPin = 12;
////Pin connected to DS of 74HC595
int dataPin = 11;
byte data1;
byte data2;
byte data3;
void setup() {
Serial.begin(57600);
pinMode(latchPin, OUTPUT);
}
void loop() {
if(Serial.available() > 2) {
data1 = Serial.read();
data2 = Serial.read();
data3 = Serial.read();
digitalWrite(latchPin, 0);
shiftOut(dataPin, clockPin, data1);
shiftOut(dataPin, clockPin, data2);
shiftOut(dataPin, clockPin, data3);
digitalWrite(latchPin, 1);
}
}
void shiftOut(int myDataPin, int myClockPin, byte myDataOut) {
int i=0;
int pinState;
pinMode(myClockPin, OUTPUT);
pinMode(myDataPin, OUTPUT);
digitalWrite(myDataPin, 0);
digitalWrite(myClockPin, 0);
for (i=7; i>=0; i--) {
digitalWrite(myClockPin, 0);
if ( myDataOut & (1<<i) ) {
pinState= 1;
}
else {
pinState= 0;
}
digitalWrite(myDataPin, pinState);
digitalWrite(myClockPin, 1);
digitalWrite(myDataPin, 0);
}
digitalWrite(myClockPin, 0);
}