-
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
- A fociról könnyedén, egy baráti társaságban
- Polgári repülőgép-szimulátorok
- Melyik tápegységet vegyem?
- Eredeti játékok OFF topik
- Apple iPhone Air - almacsutka
- Vivo X200 Pro - a kétszázát!
- Formula-1
- Házimozi belépő szinten
- Kínai és egyéb olcsó órák topikja
- AMD K6-III, és minden ami RETRO - Oldschool tuning
- További aktív témák...
- IPHONE 16 PRO MAX 256 GB Fehér titán Kártyafüggetlen
- 200 ezerrel ár alatt! A széria királya! A legmaxosabb 5080! Asus rog astral !
- ESZMÉLETLEN JÓ ÁRON MINDEN VAN! Amit csak szeretnél írd meg, szinte biztos hogy van! GARIS ÚJ cuccok
- AMILYEN GAMER PC-t AKARSZ AZT ÉN ÁR ALATT ÖSSZERAKOM NEKED! TELEVAGYOK KOMPONENSEKKEL! ÍRJ BÁTRAN!
- AMILYEN GAMER PC-t AKARSZ AZT ÉN ÁR ALATT ÖSSZERAKOM NEKED! TELEVAGYOK KOMPONENSEKKEL! ÍRJ BÁTRAN!
- Tablet felvásárlás!! Apple iPad, iPad Mini, iPad Air, iPad Pro
- 1MII B03PRO+ Receiver, Transmitter LDAC
- Bomba ár! Lenovo ThinkPad X230 i5-3GEN I 8GB I 256SSD I 12,5" HD I Cam I W10 I Garancia!
- BESZÁMÍTÁS! MSI B450 R5 5500 16GB DDR4 512B SSD GTX 1070 8GB Chieftec BD-25B-350GPB Zalman 500W
- Apple iPad Pro 11 (2018) 64GB, Kártyafüggetlen, 1 Év Garanciával
Állásajánlatok
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest
Cég: Laptopműhely Bt.
Város: Budapest