I have two input devices - a timing gear sensor and an analog potentiometer.
If I just run the "ReadTimingGear" or just run the "CheckEngineLoad" functions individually I get the results I expect. However if I allow both functions to run in the same code the IDE crashed.
Should I be using a digital pot rather than an analog one for this excersise?
Thanks, Daniel.
int SensorValue = 3; // Read A2 pin for throttle load value from the potentiometer
float ThrottleLoad = 0; // Stores the current load of the throttle
int SetPin4 = 4; // LED connected to digital pin 13
int SetPin2 = 2; // pushbutton connected to digital pin 7
int Pin2Read = 0; // variable to store the read value
float SetPin3 = 3;
float Pin3Read = 0;
int Last2PinRead = 0;
int SetPin6 = 6;
int Pin6Read = 0;
int Last6PinRead = 0;
unsigned long PreviousMillis = 0;
unsigned long CurrentMillis = 0;
unsigned long RPM = 0;
int CounterOne = 0;
void setup(void)
{
//pinMode(led_pin, OUTPUT);
Serial.begin(115200);
pinMode(SetPin4, OUTPUT); // sets the digital pin 4 as output
pinMode(SetPin6, INPUT_PULLUP); // sets the digital pin 2 as input
pinMode(SetPin3, INPUT_PULLUP);
sei();
}
void loop()
{
attachInterrupt(digitalPinToInterrupt(2), ReadTimingGear, RISING);
CheckEngineLoad();
}
void ReadTimingGear() {
CurrentMillis = millis();
Serial.println(CurrentMillis);
}
void CheckEngineLoad()
{
ThrottleLoad = analogRead(SensorValue) * (100.0 / 1023.0);
Serial.println(ThrottleLoad);
}
jremington:
Extremely unlikely. Tell us what actually happened.
Thanks for the reply and thanks for pointing out the problems with my code.
What actually happens to the IDE is that it totally freezes. As with a non responding window. I am thinking that maybe it is just tied up processing but if I comment out one function call or the other everything runs as expected it's only when I allow both functions to be called that the problem is shown.