Arduino to Serial Register

Hey all,

Wow how’s that for a first impression. Having to reply to myself because I can’t even post a whole message to the forum without screwing it up.

OK… now I’m ready:

HEY EVERYONE!

I’m trying to decipher these cascading Serial Register tutorials (mainly Code Sample 2.2 – 2 Byte One By One)

All I really want is to pipe a number between 0 and 72 into my arduino and get a SINGLE corresponding led to light up.
I’m getting close but I can’t completely get my head around the bitwise masking.

So with the following I can’t isolate a single LED. Each SR lights the same LED in each 8bit group.

Know what I mean?!
Me neither. Here’s the code:

//Pin connected to ST_CP of 74HC595
int latchPin = 4;
//Pin connected to SH_CP of 74HC595
int clockPin = 3;
////Pin connected to DS of 74HC595
int dataPin = 7;

int maxval;
int srval;

void setup() {

//set pins to output because they are addressed in the main loop
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
Serial.begin(9600);
}

void loop() {

srval = 0;
maxval = 0;

// check if data has been sent from the computer
if (Serial.available()) {
// read the most recent byte (which will be from 0 to 255)
maxval = Serial.read();

srval = 1 << maxval;

Serial.print("out to SR: ");
Serial.println(srval, BIN);

digitalWrite(latchPin, LOW);

shiftOut(dataPin, clockPin, MSBFIRST, srval);

digitalWrite(latchPin, HIGH);
delay(1000);

}

}

maxval = Serial.read(); 

srval =  1 << maxval;

I’m guessing you are using some sort of terminal application to enter numbers to indicate which LED you want lit? If so, you need an ASCII-to-integer conversion in here somewhere. The character ‘0’ has an ASCII value of 3010. Then there’s the added complication of numbers with multiple digits.

Single digits ASCII-to-binary conversion is simple: b = c - '0'; will place the binary value for character c into integer variable b.

Of course, if you are transmitting binary values with some application, my comments are completely useless.

-j

Sorry J,

I should have included that bit of info. I'm using the serial object in Max to send these ints.

Should I be doing some sort of switch/case to parse these out into 8 bit chunks in order to single out a single SR?

Thanks for your help!

Sorry, but I don't know Max, so maybe someone familiar with it can jump in here and help us out.

-j