-
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
-
lanszelot
addikt
válasz
lanszelot #20311 üzenetére
Meg kell várjam a Nano -mat, mert lehet, hogy a RotEnc hibás.
A linkelt pelda sem működik, pedig annak már kellene.
/SW nincs bekötve, így semmit se jelent az a pár sor jelenleg/keses változó vagy nem változik, vagy nem kerül be a delay -be.
/*LED input*/
#define led 0
/*rotary encoder input*/
// Rotary Encoder Inputs
#define CLK 2
#define DT 1
#define SW 4
int counter = 0;
int currentStateCLK;
int lastStateCLK;
int keses = 1000;
String currentDir ="";
unsigned long lastButtonPress = 0;
void setup() {
// Set encoder pins as inputs
pinMode(CLK,INPUT);
pinMode(DT,INPUT);
pinMode(SW, INPUT_PULLUP);
/*LED pin output*/
pinMode (led, OUTPUT);
// Setup Serial Monitor
Serial.begin(9600);
// Read the initial state of CLK
lastStateCLK = digitalRead(CLK);
}
void loop() {
// Read the current state of CLK
currentStateCLK = digitalRead(CLK);
// If last and current state of CLK are different, then pulse occurred
// React to only 1 state change to avoid double count
if (currentStateCLK != lastStateCLK && currentStateCLK == 1){
// If the DT state is different than the CLK state then
// the encoder is rotating CCW so decrement
if (digitalRead(DT) != currentStateCLK) {
counter --;
currentDir ="CCW";
if(keses > 100){
keses = keses-100;
}
} else {
// Encoder is rotating CW so increment
counter ++;
currentDir ="CW";
keses = keses+100;
}
Serial.print("Direction: ");
Serial.print(currentDir);
Serial.print(" | Counter: ");
Serial.println(counter);
}
/*red led on off*/
digitalWrite(led, HIGH);
delay(keses);
digitalWrite(led, LOW);
delay(keses);
// Remember last CLK state
lastStateCLK = currentStateCLK;
// Read the button state
int btnState = digitalRead(SW);
//If we detect LOW signal, button is pressed
if (btnState == LOW) {
//if 50ms have passed since last LOW pulse, it means that the
//button has been pressed, released and pressed again
if (millis() - lastButtonPress > 50) {
Serial.println("Button pressed!");
}
// Remember last button press event
lastButtonPress = millis();
}
// Put in a slight delay to help debounce the reading
delay(1);
}
Új hozzászólás Aktív témák
- Konkrét moderációval kapcsolatos kérdések
- A fociról könnyedén, egy baráti társaságban
- Magisk
- Autós topik
- Kerékpárosok, bringások ide!
- Borotva, szakállnyíró, szakállvágó topic
- Milyen processzort vegyek?
- Nintendo Switch 2
- Kettő együtt: Radeon RX 9070 és 9070 XT tesztje
- ASZTALI GÉP / ALKATRÉSZ beárazás
- További aktív témák...
- BESZÁMÍTÁS! MSI B450 R5 5500 16GB DDR4 512GB SSD RTX 2060 Super 8GB Rampage SHIVA TT 500W
- BESZÁMÍTÁS! GIGABYTE B660M i7 13700 32GB DDR4 512GB SSD RX 6800 16GB Thermaltake Core X5 GB 850W
- BESZÁMÍTÁS! MSI B450 R5 5500 16GB DDR4 512GB SSD RTX 2060 Super 8GB SilentiumPC Signum SG1V TT 500W
- BESZÁMÍTÁS! Asus B550M R5 5600X 32GB DDR4 512GB SSD RTX 3060 12GB THERMALTAKE Commander G41 700W
- BESZÁMÍTÁS! MSI B460M i5 10400F 32GB DDR4 512GB SSD RTX 2060 Super 8GB Zalman S4 Plus TT 500W
- 122 - Lenovo Legion Pro 5 (16ARX8) - AMD Ryzen 7 7745HX, RTX 4070 (48 hónap garancia!)
- Honor Magic6 Lite 256GB, Kártyafüggetlen, 1 Év Garanciával
- Országosan a legjobb BANKMENTES részletfizetési konstrukció! Lenovo ThinkPad L16 Gen 1 Prémium
- Bomba ár! HP ZBook Studio G5 - i9-9980H I 32GB I 1TSSD I Nvidia I 15,6" FHD I Cam I W11 I Gar
- BESZÁMÍTÁS! Lenovo ThinkPad T14 Gen 4 üzleti notebook - i7 1360P 24GB DDR5 RAM 512GB SSD Iris Xe W11
Állásajánlatok
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest
Cég: Promenade Publishing House Kft.
Város: Budapest