title: Store multiple variables to buffer with memcpy
body: <p>I'm <b>very</b> new to Arduino and I can't find any way to do the following.
  I have a typedef struct which fills up multiple values:</p>
  
  <pre><code>void loop() {
  accel.process();
  AccelerationReading accelData;
  accelData.xAxis = accel.xAxis;
  accelData.yAxis = accel.yAxis;
  accelData.zAxis = accel.zAxis;
  //Irrelevant code after this
  }
  </code></pre>
  
  <p>After the struct is filled I <code>memcpy</code> it in to the buffer:</p>
  
  <pre><code>uint8_t buffer[6];
  memcpy((void*)buffer, (void*)&amp;accelData, 6);
  </code></pre>
  
  <p>Now this works fine but I also need to read values from two analog ports and those two values also need to be added in the memcpy. The code that fills the two variables:</p>
  
  <pre><code>//New variables
  int shortflexposition;
  int longflexposition;
  //Filling up the variables.
  shortflexposition = analogRead(shortflexpin);
  longflexposition = analogRead(longflexpin);
  </code></pre>
  
  <p>The accelData contains 6 bytes of raw values and now I want to add shortflexposition and longflexposition <b>after</b> these bytes. The values in the variables shortflexposition and longflexposition are always between 0 and 1023.
  How exactly should I add those other variables in the memcpy? I've tried for example:</p>
  
  <pre><code>uint8_t buffer[8];
  memcpy((void*)buffer, (void*)&amp;accelData + shortflexposition, 8);
  </code></pre>
  
  <p>But this seems to rather add values to eachother than adding them to the next bytes or something. So, how do I add new variables on the next byte positions with memcpy?</p>
  
  <p>Thanks!
  Yenthe</p>
  
  <p><b>Update:</b>
  This is an attempt at the code from Lundin..</p>
  
  <pre><code>typedef union
  {
    struct s
    {
      AccelerationReading accelData;
      uint16_t shortflexposition;
      uint16_t longflexposition;
    };
   uint8_t raw_data [sizeof(struct s)];
   } my_data;
  
  void setup() {
  // Bean Serial is at a fixed baud rate. Changing the value in Serial.begin() has no effect.
  Serial.begin();   
  accel.init();
  }
  
  void loop() {
    accel.process();
    AccelerationReading accelData;
    my_data data;
    data.accelData.xAxis = accel.xAxis;
    data.accelData.yAxis = accel.yAxis;
    data.accelData.zAxis = accel.zAxis;
  
    //Get flex readings
    int shortflexposition;
    int longflexposition;
  
    //Read the position of the flex sensor (0 to 1023?)
    data.shortflexposition = analogRead(shortflexpin);
    data.longflexposition = analogRead(longflexpin);
    my_data some_other_data = data;
  
    uint8_t buffer[6];
    memcpy((void*)buffer, (void*)&amp;accelData, 6);
    Bean.setScratchData(1,buffer,6);
    Bean.sleep(1000);
  }
  </code></pre>
  
  <p>But gives the following errors:</p>
  
  <pre><code>GetReader.ino: In function 'void loop()':
  GetReader.ino:54:8: error: 'union loop()::my_data' has no member named 'accelData'
  GetReader.ino:55:8: error: 'union loop()::my_data' has no member named 'accelData'
  GetReader.ino:56:8: error: 'union loop()::my_data' has no member named 'accelData'
  GetReader.ino:63:8: error: 'union loop()::my_data' has no member named 'shortflexposition'
  GetReader.ino:64:8: error: 'union loop()::my_data' has no member named 'longflexposition'
  </code></pre>