-
PROHARDVER!
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
- Szép Dell Precision 5560 Slim Tervező Vágó Laptop -70% 15,6" i7-11850H 64/1TB RTX A2000 4GB UHD 4K
- Acer Nitro V 16 AI Gamer Laptop! Ryzen 7 260/RTX 5070/32gb DDR5/2TB SSD/2560x1600/180hz/Beszámítok!
- Szép Dell Precision 5560 Slim Tervező Vágó Laptop -70% 15,6" Xeon W-11955M 64/1TB RTX A2000 4GB FHD+
- AOC CQ27G2S Monitor (2K/VA/165hz)
- Samsung C27F396FHR Monitor
- Új! Számla + 1-3ÉV Gari! Áfás! Gamer PC - Számítógép! R5 9600X / RX 9070XT / 32GB DDR5 / 1TB SSD M.2
- ÁRGARANCIA! Épített KomPhone Ryzen 5 7600X 32/64GB DDR5 RTX 5060Ti 8GB GAMER PC termékbeszámítással
- ÁRGARANCIA!Épített KomPhone Ryzen 7 7700X 32/64GB RAM RX 7800 XT 16GB GAMER PC termékbeszámítással
- ÁRGARANCIA! Épített KomPhone Ryzen 5 9600X 32/64GB RTX 5070 12GB GAMER PC termékbeszámítással
- Egyedi ékszerdobozka
Állásajánlatok
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest
Cég: Promenade Publishing House Kft.
Város: Budapest