Summing together 10 readings


I’m taking in sensor data from the serial port using the function below.

How could I take in 10 readings and sum them together?


void showNewData() {
  if (newData == true) {
    char* reading = receivedChars + 1;
    sensorReading = atoi(reading);
    newData = false;

Using the + operator, or the += compound operator.

(that was just a snippet of the full answer)

Create a global sum variable, set it to zero before the readings and then what AWOL said.

Have a look here - it looks like this guy has a very similar problem