Hi Guys
My first sort of scrapped together code.
Im waving a magnet in front of a hall effect sensor, most of it is working.
I have 3 variables,
- a live value of the sensor (Hall01live) to either 0 or 1 (working when I wave magnet)
- setting a value of what the sensor was (Hall01was) at the end of a if statement (not working)
- setting an angle and a variable of the same name, starting at 200, expecting it to change to 199 when I wave a magnet in front of it, and it to stay as 199 until I remove the magnet then it returns to 200
No idea what I am doing wrong, please help
int Hall01was = 0;
int Hall01live = 0;
int angle = 200;
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
//detecting magnet, setting Hall01 to 1 or 0
if ( sensorValue > 200) Hall01live = 1;
if (sensorValue < 200) Hall01live = 0;
Hall01was=Hall01was;
//angle test
//this tests to see if there is a change, changes the variable angle and then reset the check ('was')
if (Hall01was = 0 && Hall01live = 1){ angle-1 ; Hall01was ==1;}
//this tests to see if there is a change, changes the variable angle and then reset the check ('was')
if (Hall01was == 1 && Hall01live == 0){ angle -1 ; Hall01was ==0;}
//display stuff
Serial.println ("Hall01was");
Serial.println(Hall01was);
Serial.println ("Hall01live");
Serial.println(Hall01live);
Serial.println("angle");
Serial.println(angle);
Serial.println("sensor");
Serial.println(sensorValue);
delay(2000);
}
int Hall01was = 0;
int Hall01live = 0;
int angle = 200;
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
//detecting magnet, setting Hall01 to 1 or 0
if ( sensorValue > 200) Hall01live = 1;
if (sensorValue < 200) Hall01live = 0;
//angle test
if (Hall01was == 0 && Hall01live == 1){ angle -1 ;}
if (Hall01was == 1 && Hall01live == 0){ angle +1 ;}
Serial.println ("Hall01was");
Serial.println(Hall01was);
Serial.println ("Hall01live");
Serial.println('Hall01live');
Serial.println("angle");
Serial.println(angle);
Serial.println("sensor");
Serial.println(sensorValue);
delay(2000); // delay in between reads
}