using interrupt to switch between modes in arduino

Thread Starter

justtrying

Joined Mar 9, 2011
439
Back to try and find a better solution for my previous problem...

We got the switch to work when the device is being turned on, but we want to configure it so that the modes can be switched during operation. Because there are while loops and infinite loops, we found it difficult to come up with a way to monitor the switch and now I am trying to use interrupts. I got a code, which seems to be limping along, but I have to close and reopen serial port to see the interrupt kick in. I am not sure what is wrong.

Rich (BB code):
 void setup() { 
  
  Serial.begin(9600);          // start serial communication
  pinMode(2, INPUT);          // make pin 2 an input pin
  
  // attach routine Learn() to ext interrupt 0, and 
  // generate it when the associated pin (7) falls from
  // HIGH to LOW. Alternatives are LOW, CHANGE, RISING.
  attachInterrupt(0, Learn, CHANGE);
}


void loop() {
  Trigger();
  delay(200);
}
So the way I see it is that it will run in trigger mode until interrupt is executed.

One thing I saw is that when interrupt happens, everything freezes, both Trigger and Learn functions uses millis to determine sampling rate, so maybe I cannot even use this approach? Both are large functions that call other functions, so I am not posting the bloated thing here.

Any suggestions are appreciated. What we want to do is to allow the user to switch from Trigger mode into Learn, the way it is now, you have to turn the device off first. The problem seems to be due to the fact that Trigger mode is a while(true) loop to make it constantly gather data.
 
Top