im planning a program that uses several (~ 16 input D channels) digital input channels and uses if slopes to identify what to do.
I thought about reading all inputs at the beginning and then creating a digital string (for example 10100100101100) to decide the case. So the length is always the same... start will be 0000000... . I am new to arduino and so far i can create the vector / array and write the inputs in there. But i dont know how to convert the vector
for example
int DV[] = {0,0,0};
into a string
000
Or is there a better way to do this?
I have also some cases where i want to use an analog input in addition
for example 101 and AnalogIn <=500 or something like that.
int DV[] = {0,0,0};
void setup()
{
Serial.begin(115200);
Serial.writeln("Start");
for (int i=0; i< 3; i++)
{
Serial.write(DV[i]);
Serial.write(","); // the comma is a separator to make interpreting on the other side easier.
}
Serial.writeln();
}
void loop(){} // loop is empty
No way should you use a String to hold that data. Use a byte array, or use an unsigned int with 1 bit per input (if there are no more than 16 inputs), or an unsigned long with 1 bit per input (if there are no more than 32 inputs). Something like this:
unsigned int readings = 0;
for (int i=0; i <= 3; i++)
{
readings <<= 1;
TempVal=digitalRead(Dchans[i]);
if (TempVal==HIGH)
{
readings |= 1;
}
}
...
if (readings = B00000101) ...