i am presently working on a shift resistor and was trying to get a string from serial monitor like "10110100"(basically arrangement of led's i want to light up). i converted an number(int) corresponding to the byte and got it to work with the shift resistor. i am having problems with sending a string and converting it as it is to byte and then int.
//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;
String inString = "";
void setup() {
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
Serial.begin(9600);
}
void loop()
{
int inChar = Serial.read();
if (isDigit(inChar)) //making the string from serial port.
{
inString += (char)inChar;
if(inString.length() ==8)//defining string to be 8 bits long.
{
int x=int(byte(inString.toInt()));
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, x); //sending the value to the shift resistor
digitalWrite(latchPin, HIGH);
Serial.println(x);//for conformation getting the value on serial monitor
inString="";
}
}
}
may by the problem is in the part "int x=int(byte(inString.toInt()));"