-
Fototrend
Arduino hardverrel és szoftverrel foglakozó téma. Minden mikrovezérlő ami arduinoval programozható, és minden arduino program, board, és hardverrel kapcsolatos kérdések helye.
Új hozzászólás Aktív témák
-
Ez a példa félig működik csak jól, mert ugyan minden változásra reagál, de a számlálást ugyanúgy a loopban végzi. A számlálást be kell tenni az isr-be, akkor jó lesz.
Próbáld ezt:volatile boolean TurnDetected;
volatile boolean up;
volatile long virtualPosition=0;
const int PinCLK=2; // Used for generating interrupts using CLK signal
const int PinDT=3; // Used for reading DT signal
const int PinSW=4; // Used for the push button switch
void isr () { // Interrupt service routine is executed when any CHANGE transition is detected on CLK
volatile boolean CLK = digitalRead(PinCLK);
volatile boolean DT = digitalRead(PinDT);
up=((!CLK && DT)||(CLK && !DT));
if (up)
virtualPosition++;
else
virtualPosition--;
TurnDetected = true;
}
void setup () {
pinMode(PinCLK,INPUT);
pinMode(PinDT,INPUT);
pinMode(PinSW,INPUT);
attachInterrupt (0,isr,CHANGE); // interrupt 0 is always connected to pin 2 on Arduino UNO
Serial.begin (9600);
Serial.println("Start");
}
void loop () {
if (!digitalRead(PinSW)) { // check if pushbutton is pressed
virtualPosition=0; // if YES, then reset counter to ZERO
Serial.print ("Reset = "); // Using the word RESET instead of COUNT here to find out a buggy encoder
Serial.println (virtualPosition);
}
if (TurnDetected) { // do this only if rotation was detected
TurnDetected = false; // do NOT repeat IF loop until new rotation detected
Serial.print ("Count = ");
Serial.println (virtualPosition);
}
}
Új hozzászólás Aktív témák
- HIBÁTLAN iPhone 13 mini 256GB Pink -1 ÉV GARANCIA - Kártyafüggetlen, MS3408
- Samsung Galaxy S24 FE 128GB, Kártyafüggetlen, 1 Év Garanciával
- GYÖNYÖRŰ iPhone 11 128GB Red -1 ÉV GARANCIA - Kártyafüggetlen, MS3127, 100% Akkumulátor
- Apple iPhone 14 pro 128GB,Újszerű,Dobozával, 12 hónap garanciával
- billentyűzetek - kiárusítás - Logitech, Corsair, ASUS
Állásajánlatok
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest
Cég: Laptopműhely Bt.
Város: Budapest
ekkold
