Edit: after posting, I realized it may be better if I do the processing on my pc, and send a single byte instead of the pattern itself. I think I'll work on that. I'm still curious how I'd convert it if I had to in another scenario (i.e. reading 8 sensors, and then sending the data to the shift register to turn on LEDs if certain conditions are met)
I'm looking to receive a data via serial from my PC and then send that data to a shift register to light up 8 leds. I'm really new to this aspect, but I've been researching this online but now have come to a standstill.
For example, I want to send "s11100111" to my arduino through serial and have it send 111001111 to the shift register.
So far I've had luck on another project when I declare my pattern such as: byte pattern = {B11100111} but I'm unsure how to convert my incoming serial data into that.
Here's my code I have so far. It receives the data from serial and stores it in an array. Is there anything major I should change? How would I go about converting my array into something I could easily shiftOut (or should I be storing it different in the first place?) Thanks
void setup()
{
Serial.begin(9600);
}
void loop()
{
int serialpos = 0;
int mybits[8];
while (Serial.available() > 8) {
if (Serial.read() == 's') {
Serial.println("Starting Sequence.");
while (serialpos < 8) {
mybits[serialpos] = Serial.read();
serialpos++;
}
Serial.print("Sequence Received: ");
for (int xloop = 0; xloop < 8;xloop++) {
Serial.print(mybits[xloop],DEC);
}
Serial.println("");
serialpos = 0;
// *
// Here is where I'm looking to convert the mybits array into something I can shiftOut
//*
}
}
}