Go Down

Topic: How to change from standard to other digital input (Read 231 times) previous topic - next topic

Midway

May 25, 2013, 06:42 pm Last Edit: May 25, 2013, 06:57 pm by Midway Reason: 1
I like to use Digital input 9 and 10
but dont know how to change in this code

Code: [Select]

static boolean rotating=false;
void rotEncoder()
{
 rotating=true; // If motion is detected in the rotary encoder,
                // set the flag to true
}
//...

void setup() {

 // Attach Interrupts
 attachInterrupt(0, rotEncoder, CHANGE);  // ISR for rotary encoder
 //...
 //...
}

void loop() {
 //...

  while(rotating)
 {
   delay(2);  // debounce by waiting 2 milliseconds
              // (Just one line of code for debouncing)
   if (digitalRead(4) == digitalRead(2))  // CCW
   StepDR2--;
   else                          // If not CCW, then it is CW
   StepDR2++;

   rotating=false; // Reset the flag
 }
}


http://playground.arduino.cc/Main/PinChangeInt
Yes, i know.. but how ?...

johnwasser

The only two 'external' interrupts on the Arduino UNO are 0 and 1 on pins 2 and 3.

If you want to use other pins you will have to use Pin Change Interrupts.  You can find out more about them with Google.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Go Up