#define encoder0PinA 2 #define encoder0PinB 3 volatile unsigned int encoder0Pos = 0; void setup() { pinMode(encoder0PinA, INPUT); pinMode(encoder0PinB, INPUT); // encoder pin on interrupt 0 (pin 2) attachInterrupt(0, doEncoderA, CHANGE); // encoder pin on interrupt 1 (pin 3) attachInterrupt(1, doEncoderB, CHANGE); Serial.begin (9600); } void loop(){ //Do stuff here } void doEncoderA(){ // look for a low-to-high on channel A if (digitalRead(encoder0PinA) == HIGH) { // check channel B to see which way encoder is turning if (digitalRead(encoder0PinB) == LOW) { encoder0Pos = encoder0Pos + 1; // CW } else { encoder0Pos = encoder0Pos - 1; // CCW } } else // must be a high-to-low edge on channel A { // check channel B to see which way encoder is turning if (digitalRead(encoder0PinB) == HIGH) { encoder0Pos = encoder0Pos + 1; // CW } else { encoder0Pos = encoder0Pos - 1; // CCW } } Serial.println (encoder0Pos, DEC); // use for debugging - remember to comment out } void doEncoderB(){ // look for a low-to-high on channel B if (digitalRead(encoder0PinB) == HIGH) { // check channel A to see which way encoder is turning if (digitalRead(encoder0PinA) == HIGH) { encoder0Pos = encoder0Pos + 1; // CW } else { encoder0Pos = encoder0Pos - 1; // CCW } } // Look for a high-to-low on channel B else { // check channel B to see which way encoder is turning if (digitalRead(encoder0PinA) == LOW) { encoder0Pos = encoder0Pos + 1; // CW } else { encoder0Pos = encoder0Pos - 1; // CCW } } } aşşağıdaki hatayı veriyor. sketch_jan13b.ino: In function ‘void loop()’: sketch_jan13b.ino:22:18: error: a function-definition is not allowed here before ‘{’ token sketch_jan13b.ino:70:1: error: expected ‘}’ at end of input Derleme Hatası mümkünse ideye atıp sizde dener misiniz ? ide versiyon problemimi acaba ? kodlarda müdahalem yoktur. bu kodlar üzerinden giderek bi counter yazacağım ama bi türlü burdaki hatayı çözemedim..
void loop() { //Do stuff here } şu şekilde yazmayı deneyin sorun düzelecektir.
Teşekkür ederim . Farklı bi örnek uygulama buldum çalıştırdım ama 4096 puls encoder baya bi puls kaçırdı, bide bunda deneyelim.