Odd output in serial monitor using char

I am wondering why my code below gets the correct values as it loops (2,5 and 5) but once I place them in the array it comes out 157?

char results[2];
char resultVals[2];
int i = 0;
int x = 0;

void setup() {
  SerialUSB.begin(); 
  strip.begin();
}

void loop() {
  while (SerialUSB.available())
    {
        char recieved = SerialUSB.read();

        if (recieved == '\n')
        {
          SerialUSB.println("found new line");
          if (x == 2) {
            //Finished captureing ALL 3 values (xxx xxx xxx)
            x = 0;
            i = 0;
            memset(results, 0, sizeof(results));
            SerialUSB.println("end");
          } else {
            SerialUSB.print("capture the 3 values: ");
            SerialUSB.print(results[0] + results[1] + results[2]);
            SerialUSB.println("");
            //capture the value
            resultVals[x] = results[0] + results[1] + results[2];
            x++;
            i = 0;
          }
        } else {
          //Not the full XXX yet so keep looping.
          SerialUSB.print("looping: ");
          SerialUSB.print(recieved);
          SerialUSB.println("");
          results[i] += recieved;
          i++;
        }
    }

    SerialUSB.delay(10);
}

The serial output is this:

looping: 2
looping: 5
looping: 5
found new line
capture the 3 values: 157
looping: 2
looping: 5
looping: 5
found new line
capture the 3 values: 313
looping: 2
looping: 5
looping: 5
found new line
end

What is the reason why its not taking in 255 and instead putting 157?

strings and chars don't add with a +. What you've done is add their ascii codes up like numbers.

If you want to print a char array just print it. Null terminate it first, then just:

Serial.println(results);

It gives a compile error of:

invalid conversion from 'char*' to 'char' [-fpermissive]

for

resultVals[x] = results;

What is that line supposed to do? Are you hoping to cram all 3 characters into one character? Not gonna happen. I told you how to print it. Do you need it as a number? Try atoi.

Yeah... still dont get it sorry.

Maybe if I knew what you wanted the code to do...

This is what i ended up with:

#include <DigiCDC.h>
#include <Adafruit_NeoPixel.h>
//                                          |-How many LEDs?
//                                          |  |-What Arduino Pin?
//                                          |  |   |-Default
//                                          |  |   |
//                                          |  |   |
Adafruit_NeoPixel strip = Adafruit_NeoPixel(1, 2, NEO_GRB + NEO_KHZ800);
int R,G,B;
int x = 0;

void setup() {
  SerialUSB.begin(); 
  strip.begin();
}

void loop() {
  int angle = 0;
  
  while (SerialUSB.available())
    {
        char recieved = SerialUSB.read();
        
        if (recieved == '\n')
        {          
          if (x == 2) {
            //Get BLUE value
            B = angle;
            //Finished captureing ALL 3 values (xxx xxx xxx)            
            fiao(R, G, B, 10);
            //Now clean up for another call
            x = 0;
            R = 0;
            G = 0;
            B = 0;
          } else if (x == 0) {
            //Get RED value
            R = angle;
            x++;
          } else if (x == 1) {
            //Get GREEN value
            G = angle;
            x++;
          }
        } else {
          //Not the full XXX yet so keep looping.
          int c = (int)recieved - 48;
          angle *= 10;
          angle += c;
        }
    }

    SerialUSB.delay(10);
}

void fiao(uint8_t red, uint8_t green, uint8_t blue, uint8_t wait) {
  for(uint8_t b=0; b <255; b++) {
     for(uint8_t i=0; i < strip.numPixels(); i++) {
        strip.setPixelColor(i, red*b/255, green*b/255, blue*b/255);
     }
     strip.show();
     delay(wait);
  };

  for(uint8_t b=255; b > 0; b--) {
     for(uint8_t i=0; i < strip.numPixels(); i++) {
        strip.setPixelColor(i, red*b/255, green*b/255, blue*b/255);
     }
     strip.show();
     delay(wait);
  };
};
  SerialUSB.begin();

Seems odd that no baud rate is given.

econjack:

  SerialUSB.begin();

Seems odd that no baud rate is given.

The SerialUSB interface uses USB speeds, not Serial speeds.