It was not an assumption, it was a fact: the code you originally posted did not compile. Do you think that insulting the people trying to help you is going to encourage them to offer more help?
The code i posted did (with respect to needing the rest of course) going back through and reading the thread i will admit i made the error of figuring out who PaulS was talking too, which was not me. I am sorry for that, alot of hassle over more then one person getting confused.
To help everyone understand what i need, i will make a video here in a sec and i will tell you the goal of the project.
Goal- My goal with this project is a auto shut off blinker for a motorcycle. I will read the angle of the bike at all times. Then when the user hits the blinker (left or right) i save that instance of angle. Since you have to lean to turn on a motorcycle the angle will only increase.
While the angle is increasing it is compared to the saved angle, once the live angle is less then the saved angle value the blinker is turned off.
That is the bases of the project. I am just not able to save the value for some reason. When ever i save it, the value follows along the live value.
(Is this because i have it in the main and so it is always looping? Testing that idea now with making a new function.)
EDIT: Changed the code up alittle to try to see what is going on. Here is the updated code and the video with updated code will be attached.
#include <serLCD.h>
#include <SoftwareSerial.h>
#include <LiquidCrystal.h>
#include <math.h>
int oldval=0; //sec value for the button
int state1=0; //state the button is in
int val = 0; //first value for the button
const int button = 7; //pin for the push button (for testing)
// these constants won't change:
const int xPin = 2; // X output of the accelerometer
const int yPin = 3; // Y output of the accelerometer
//Button Left And Right pins (for use later)
int right = 4;
int left = 5;
// Set pin to the LCD's rxPin
int pin = 1;
serLCD lcd(pin);
int Xraw, Yraw;
double xGForce, yGForce, Xangle, Yangle;
double saveY, saveX, state;
void setup() {
// initialize serial communications:
Serial.begin(9600);
// initialize the pins connected to the accelerometer
// as inputs:
pinMode(xPin, INPUT);
pinMode(yPin, INPUT);
Serial.write(0xFE); //command flag
Serial.write(0x01); //clear command.
delay(10);
Serial.print("Lets Begin");
delay(1000);
}
void loop() {
// lcd.clear();
Serial.write(0xFE); //command flag
Serial.write(0x01); //clear command.
delay(10);
// variables to read the pulse widths:
int pulseX, pulseY;
// variables to contain the resulting accelerations
int accelerationX, accelerationY;
// read pulse from x- and y-axes:
pulseX = pulseIn(xPin,HIGH);
pulseY = pulseIn(yPin,HIGH);
Xraw = pulseIn (xPin, HIGH);
Xraw = pulseIn (xPin, HIGH);
Yraw = pulseIn (yPin, HIGH);
Yraw = pulseIn (yPin, HIGH);
// Calculate G-force in Milli-g's.
xGForce = (( Xraw / 10 ) - 500) * 8;
yGForce = (( Yraw / 10 ) - 500) * 8;
// Calculate angle (radians) for both -x and -y axis.
Xangle = asin ( xGForce / 1000.0 );
Yangle = asin ( yGForce / 1000.0 );
// Convert radians to degrees.
Xangle = Xangle * (360 / (2*M_PI));
Yangle = Yangle * (360 / (2*M_PI));
//save angle when button is pushed, then compare to live reading send a zero once live reading
//is below saved angle
Serial.print("Y Angle: ");
Serial.print(Yangle);
val= digitalRead(button); //Read input
if ((val==HIGH) && (oldval==LOW)){
test(saveY);
Serial.print(saveY);
} else if (Yangle <= -10) {
Serial.write(0xFE); //command flag
Serial.write(192); //position
Serial.print(saveY);
delay(150);
} else {
Serial.write(0xFE); //command flag
Serial.write(192); //position
Serial.print(saveY);
delay(150);
}
}
int test(int saveY) {
Serial.write(0xFE); //command flag
Serial.write(192); //position
saveY=Yangle;
Serial.print(saveY);
delay(150);
return saveY;
}
Only the bottom has been changed. I added a function that i thought would save the value and keep it there till the button is pressed again but i have the same problem as before.
Here is the Youtube link. Testing code - YouTube