I'm pretty new to programming for Arduino, and am slightly confused about how I can use structures with functions.
Below is an example - I have 2 sets of data stored in a structure, struct1 - firstSet and secondSet. I want to take each of these sets, and apply the function to them, changing all values. I then want to print the new values to the console, and the numbers should grow larger with each iteration, firstSet twice as fast as secondSet.
This doesn't happen, and the initial values are printed over and over again. I'm not sure what I need to do to feed those values back out to their original structures.
I've been looking at adding a return line, and also changing void to something else (int and void*), but I really can't seem to work this out. Is it even possible? Alternatively is there a better way to do this? Thanks in advance!
#include "Arduino.h"
//The setup function is called once at startup of the sketch
struct struct1
{
int val1 = 1;
int val2 = 2;
int val3 = 3;
};
struct1 firstSet;
struct1 secondSet;
void func1(struct struct1)
{
struct1 dataSet;
dataSet.val1 = dataSet.val2;
dataSet.val2 = dataSet.val3;
dataSet.val3++;
}
void setup()
{
Serial.begin(9600);
while (! Serial);
Serial.println("Console Online");
}
void printAll()
{
Serial.println(firstSet.val1);
Serial.println(firstSet.val2);
Serial.println(firstSet.val3);
Serial.println("---");
Serial.println(secondSet.val1);
Serial.println(secondSet.val2);
Serial.println(secondSet.val3);
Serial.println("---END---");
}
// The loop function is called in an endless loop
void loop()
{
func1(firstSet);
func1(firstSet);
func1(secondSet);
printAll();
delay (1000);
}