I have a code I'm using to calibrate when its pushed and held for more than 3 seconds which works great under normal conditions.
int reading = digitalRead(buttonPin);
if(reading != lastButtonState){
lastDebounceTime = millis();}
if((millis() - lastDebounceTime) > debounceDelay) {
if(reading != buttonState) { buttonState = reading;
if(buttonState == HIGH) {
ledState = !ledState;
}}
digitalWrite(LED, ledState);
lastButtonState = reading;}
while(digitalRead(buttonPin) == HIGH){
calibrate();
The above code works great until I added an interrupt for the rpm. The code for rpm by itself works great but somehow seems to be interfering. The serial monitor display s no data at all when the rpm is connected and voltage measured at the normally open end of the switch is high when it should be low. It doesn't make any sense to me. I have the RPM on interrupt 1. and the switch is on interrupt 3. (I'm using a mega)
rpm code is this simple...
if (millis() - lastmillis == 1000) {
detachInterrupt(1);
rpm = rpmcount*60;
rpmcount = millis();
attachInterrupt(1, rpm_fun, RISING);}
I tried calling the buttonPin as an INPUT as a INPUT_PULLUP and as an Interrupt all with the similar results. When its assigned as an INPUT it does display data but only for 5 seconds which is the debounceDelay I have set for the program to open the Bluetooth signal and send the saved data. confused? me too...