How do I create a sum () function for arduino? W

1

Angles ang = {0.0,46,0,91,2,134,7,179.2} were measured, the unit is deg (steps). I have to implement code that initializes the values as a global array, and then sets the void function sumCum (float arr []) {} which calculates cumulative sums (Scum = {S1, S2, S3, ..., Sn} = X1, X1 + X2, X1 + X2 + X3, ..., X1 + X2 + ... + Xn} ) of each element, and writes the values to the console. Give an example usage (invoke function plus result in console).

float acc[]={0.0,46.0,91.2,134.7,179.2}
int accSize = 5;

void setup(){
 Serial.begin(9600);
 somaCum(acc);
}
void loop(){}
void somaCum(float acc[]){
 for(int n=0;n<accSize;n++){
  //Como é que faço a função?
}
    
asked by anonymous 09.01.2018 / 19:08

1 answer

1

Does this solve your friend problem?

void somaCum(float acc[]){
for(int n=0;n<accSize;n++){
float soma = acc[n] + acc[n-1];
Serial.print(soma);
  }
}
    
09.01.2018 / 20:02