i'm quite new to this community and would like to thank all those who given their precious time to view this thread.
I have some problems trying to have the current values and the previous values. i am using punchthrough bean+ as a platform.
I am trying to compare the previous accelerometer values which needs me to use a struct type data, to the current one which the code is displayed below.
void setup()
{
Serial.begin(57600);
}
void loop()
{
int16_t x_last = abs(reading.xAxis/2);
AccelerationReading reading = Bean.getAcceleration();
int16_t x = abs(reading.xAxis/2);
int16_t y = abs(reading.yAxis/2);
int16_t z = (reading.zAxis/2);
Serial.print("x_last=");
Serial.println(x_last);
Serial.print("x=");
Serial.println(x);
delay(250);
if (x >= x_last + 10) {
Bean.setLed(0, 255, 0); //Green Led
}
}
I got a error stating that my "reading" was not declared in this scope.
I tried declaring "(reading.xAxis/2)" at the void setup section but still to no avail.
I've tried to search the forum and can't find anything related to my problem.
arduino_new:
Where did you declare your struct data?
Hi, the struct data is already self declared in the bean's program so i do not need to declare AccelerationReading as a struct type.
the AccelerationReading at the line "AccelerationReading reading = Bean.getAcceleration();" is the the struct type.
i believe reading is the int declared in the struct type, and the problem i am facing is to declare the "reading" variable to allow my code to work for the old values variable "x_last", to compare the new and old values.
BulldogLowell:
well, you are missing the creation of some objects. then...
int16_t x_last = abs(reading.xAxis/2);
AccelerationReading reading = Bean.getAcceleration();
int16_t x = abs(reading.xAxis/2);
where is `Bean` created?
where is a `reading` created?
I believe the structure is self declared inside the software where once I entered the following code, I am declaring reading. AccelerationReading reading = Bean.getAcceleration();
Thus, I’m trying to find a way to do a “previous and current value” for comparison but there’s the error which shows states that “reading” is not declared before my struct is declared. This I have no idea to solve..
KJJ:
Hmm.. to be honest, im not sure. I believed it is the structure that is predefined in the code for me to call the structure out.
You have to define it, or you have to include a library that defines it.
The single exception to that are the "native" functions included in(or by) the Arduino.h header automatically included during compilation... functions like digitalRead() and pinMode() for example.
it is really that simple, that is why your code won't compile.
BulldogLowell:
You have to define it, or you have to include a library that defines it.
The single exception to that are the "native" functions included in(or by) the Arduino.h header automatically included during compilation... functions like digitalRead() and pinMode() for example.
it is really that simple, that is why your code won't compile.
Hi i found out that AccelerationReading is a predefined structure for me to use, it is already declared in the hardware itself. i just have to call the function out and do not need to include the library.
Coming back to the problem, if i were to remove the line that declare last_x, everything would work fine. the problem is the last_x variable which i want it to store the previous value.