Hey guys I don't know what's wrong.
I want to run the loop() all the time, when I press a button "CalActive", making pin 7 go high, I want it to loop RPMCal(). Then in RPMCal() I have an if pin 7 low, blink a couple times then return to loop().
Right now It wont run RPMCal() no matter what state pin 7 is( I have a pull down resistor to 7 and button to 5v)
Also If I change: if(CalActive == HIGH){.. to if(CalActive, HIGH){.. to make sure RPMCal was working. It did go to that loop in one cycle which is what should happen. However the 1 sec delay (Blink of LED)looked like .2 sec ...hmm AHHH what im I doing wrong here.
I'm 100% positive it's a code error of mine can anyone help?
Thanks!!
int Led = 10;
int Led2 = 11;
int YIn = A0;
int XIn = A1;
int TrimIn = A3;
int Debounce = 0;
int Rpm = 0;
int RPM = 0;
int TrimVal = 0;
int Cal = 7;
int CalActive = 0;
const int AnalogInPin1 = YIn;
const int analogInPin2 = XIn;
const int analogOutPin1= Led;
const int analogOutPin2= Led2;
int sensorValue1 = 0;
int sensorValue2 = 0;
int outputValue1 = 0;
int outputValue2 = 0;
int PWR = 6;
int Ind = 13;
void RPM_()
{
RPM++;
}
void setup() {
Serial.begin(9600);
pinMode(Ind,OUTPUT);
pinMode(Led,OUTPUT);
pinMode(Cal,INPUT);
pinMode(PWR,OUTPUT);
digitalWrite(PWR, HIGH);
}
void loop() {
CalActive =(digitalRead, Cal);
int TrimVal =(analogRead, TrimIn);
sensorValue1 = analogRead(YIn);
sensorValue2 = analogRead(XIn);
Serial.print("accelerometer Y = " );
Serial.print(sensorValue1);
Serial.print("\t accelerometer X = " );
Serial.print(sensorValue2);
Serial.print("\t output 1 = ");
Serial.print(outputValue1);
Serial.print("\t output 2 = ");
Serial.println(outputValue2);
int MapX =map(sensorValue2, 470, 490, 0, 1023);
if( MapX >= TrimVal){
digitalWrite(Led, HIGH);
delayMicroseconds(100);
digitalWrite(Led, LOW);
delay(Debounce);
}
if(CalActive == HIGH){
RPMCal();
}
}
void RPMCal(){
digitalWrite(Ind, HIGH);
attachInterrupt(0, RPM_, FALLING);
delay(1000);
noInterrupts();
Rpm = (60 * RPM);
Debounce = (0.6*(60 / Rpm));
digitalWrite(Ind, LOW);
if(CalActive, LOW){
digitalWrite(Ind, LOW);
delay(50);
digitalWrite(Ind, HIGH);
delay(50);
digitalWrite(Ind, LOW);
delay(50);
digitalWrite(Ind, HIGH);
delay(50);
digitalWrite(Ind, LOW);
delay(50);
digitalWrite(Ind, HIGH);
delay(50);
digitalWrite(Ind, LOW);
loop();
}
}