- iGO Primo
- Samsung Galaxy S23 Ultra - non plus ultra
- CMF Phone 2 Pro - a százezer forintos kérdés
- Samsung Galaxy S24 Ultra - ha működik, ne változtass!
- Samsung Galaxy Watch6 Classic - tekerd!
- Milyen okostelefont vegyek?
- Samsung Galaxy Watch (Tizen és Wear OS) ingyenes számlapok, kupon kódok
- iPhone topik
- Mi nincs, grafén akku van: itt a Xiaomi 11T és 11T Pro
- Motorola Edge 50 Neo - az egyensúly gyengesége
-
Mobilarena
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
- iGO Primo
- Motorolaj, hajtóműolaj, hűtőfolyadék, adalékok és szűrők topikja
- Melyik tápegységet vegyem?
- Megjelent a Red Magic kompakt OLED kijelzős gaming táblagépe
- Autós topik
- Bambu Lab 3D nyomtatók
- Azonnali alaplapos kérdések órája
- Samsung Galaxy S23 Ultra - non plus ultra
- Milyen házat vegyek?
- Xbox Series X|S
- További aktív témák...
- LG 48C3 - 48" OLED evo - 4K 120Hz 1ms - NVIDIA G-Sync - FreeSync Premium - HDMI 2.1 - A9 Gen6 CPU
- REFURBISHED és ÚJ - HP USB-C Dock G5 docking station (5TW10AA) - 3x4K felbontás, 120Hz képfrissítés
- Medion Erazer Beast X40-hez vízhűtés (MD 60961) (ELKELT)
- 15db töltő egybe (65W + 90W) kerek végűek (ELKELT)
- IKEA (HAVREHOJ) tablet vagy laptop tartó
Állásajánlatok
Cég: CAMERA-PRO Hungary Kft
Város: Budapest
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest