Moin.
Ich habe den Code nochmal etwas aufgeräumt:
#define _Whole_Data_length 116
#define debug 0
byte pin = 2;
byte whole_array[_Whole_Data_length];
byte value;
byte array_pos=0;
unsigned long duration;
void setup()
{
pinMode(pin, INPUT);
Serial.begin(9600);
Serial.println("Give it to me...");
delay(2000);
}
void loop()
{
duration = pulseIn(pin, HIGH);
if ((duration>600)&&(duration<1000)) {
if (debug) Serial.print("1");
whole_array[array_pos] = 1;
array_pos++;
}
if ((duration>1200)&&(duration<4000)){
if (debug) Serial.print("0");
whole_array[array_pos] = 0;
array_pos++;
}
if (array_pos>=_Whole_Data_length) {
if (debug) Serial.print(";");
Serial.print(createValue(30),DEC);
Serial.print(createValue(26),DEC);
Serial.print(",");
Serial.print(createValue(22),DEC);
Serial.print(";");
Serial.print(createValue(38),DEC);
Serial.println(createValue(34),DEC);
array_pos=0;
}
}
byte createValue(byte start)
{
byte bitpos=0;
for (byte valuepos=start;valuepos<=start+3;valuepos++) {
bitWrite(value, bitpos, whole_array[valuepos]);
bitpos++;
}
return value;
}