String command;
String input[16];
byte output1;
byte output2;
const int sr_data = 7;
const int sr_shift = 10;
const int sr_clear = 11;
const int sr_store = 9;
const int sr_oe = 8;
int indexes = 0;
int stringcount = 0;
void setup() {
Serial.begin(9600);
pinMode(sr_oe ,OUTPUT);
pinMode(sr_shift ,OUTPUT);
pinMode(sr_store ,OUTPUT);
pinMode(sr_data ,OUTPUT);
pinMode(sr_clear ,OUTPUT);
digitalWrite(sr_oe, LOW);
digitalWrite(sr_shift, LOW);
digitalWrite(sr_store, LOW);
digitalWrite(sr_clear, LOW);
digitalWrite(sr_clear, HIGH);
Serial.println("Hey");
}
void loop() {
if(Serial.available()){
command = Serial.readStringUntil('\n');
if(command == "#START"){
Serial.println("Waiting for Data");
while(command != "#STOP"){
command = Serial.readStringUntil('\n');
if(command == "#LED"){
command = Serial.readStringUntil('\n');
Serial.println(command);
SplitString(command);
Shiftout();
Serial.println("Waiting for Data");
}
}
Serial.println("stop");
Store();
}
}
}
void SplitString(String str){
stringcount = 0;
while (str.length() > 0)
{
indexes = str.indexOf(',');
if (indexes == -1) // No space found
{
input[stringcount++] = str;
break;
}
else
{
input[stringcount++] = str.substring(0, indexes);
str = str.substring(indexes+1);
}
}
}
void Shiftout(){
for(int i = 0; i < 8; i++){
if(input[i] == "True") bitSet(output1, i);
else if(input[i] == "False") bitClear(output1, i);
}
for(int i = 8; i < 16; i++){
if(input[i] == "True") bitSet(output2, i - 8);
else if(input[i] == "False") bitClear(output2, i - 8);
}
shiftOut(sr_data, sr_shift, MSBFIRST, output2);
shiftOut(sr_data, sr_shift, MSBFIRST, output1);
}
void Store(){
Serial.println("store");
digitalWrite(sr_store, HIGH);
digitalWrite(sr_store, LOW);
}