void pulse(bool state) {
  uint16_t length = 200;
  if (state) {
    length = 500;
  }
  for (size_t i = 0; i < length; i++) {
    Serial.println(1023);
  }
  for (size_t i = 0; i < 1000 - length; i++) {
    Serial.println(0);
  }
}

template <size_t n> void plot(double const (& data)[n]) {
  for (double const& datum: data) {
    Serial.println(datum);
  }
}


double smooth(double const sample, double const weight) {
  static double average {sample};
  average = (1 - weight) * average + weight * sample;
  return average;
}


void setup() {
  Serial.begin(9600);

  uint8_t const signal[] {0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1};
  plot(signal);
}

void loop() {
  if (not Serial.available()) {
    return;
  }
  uint8_t sample = Serial.read() - '0';
  delay(100);
  while (Serial.available()) {
    Serial.read();
  }

  Serial.print(sample);
  Serial.print(' ');
  Serial.println(smooth(sample, 0.1));
}