Znaleziono 3 wyniki

autor: 251mz
28 gru 2020, 06:25
Forum: Arduino, Raspberry pi i inne systemy mikroprocesorowe
Temat: Arduino impulsator
Odpowiedzi: 5
Odsłony: 1805

Re: Arduino impulsator

Cudów jak delay nie używam :)
autor: 251mz
27 gru 2020, 22:08
Forum: Arduino, Raspberry pi i inne systemy mikroprocesorowe
Temat: Arduino impulsator
Odpowiedzi: 5
Odsłony: 1805

Re: Arduino impulsator

Cholera masz racje. Chyba oczy mi już zaciemnia....
Ostatni raz na C na atmega robiłem coś 10 lat temu...
Sugerowałem się tym że gościowi na filmie zlicza co 1 ....

Dlaczego znikoma?
Właśnie potrzebuje żeby co 1 kliknięcie mi dawał sygnał.
Nie chcę podłączać typowwgo enkodera optycznego a zwyły impulsator jak z linka do nawigowania w menu.
autor: 251mz
27 gru 2020, 21:08
Forum: Arduino, Raspberry pi i inne systemy mikroprocesorowe
Temat: Arduino impulsator
Odpowiedzi: 5
Odsłony: 1805

Arduino impulsator

Witam

Podłączyłem sobie impulsator 20sto impulsowy do arduino uno ze strony:
https://elty.pl/pl/p/Modul-z-enkoderem% ... Y-040/1155
I faktycznie ma 20 "kroków"

Niestety arduino liczy mi podwójnie ... :(
Tzn jedno cyknięcie to dolicza kolejne 2 zamiast 1.

Ma ktoś pomysł co robię źle?

Kod arduino ze strony http://howtomechatronics.com/tutorials/ ... e-arduino/

Kod: Zaznacz cały

/*     Arduino Rotary Encoder Tutorial
 *      
 *  by Dejan Nedelkovski, www.HowToMechatronics.com
 *  
 */
 
 #define outputA 6
 #define outputB 7

 int counter = 0; 
 int aState;
 int aLastState;  

 void setup() { 
   pinMode (outputA,INPUT);
   pinMode (outputB,INPUT);
   
   Serial.begin (9600);
   // Reads the initial state of the outputA
   aLastState = digitalRead(outputA);   
 } 

 void loop() { 
   aState = digitalRead(outputA); // Reads the "current" state of the outputA
   // If the previous and the current state of the outputA are different, that means a Pulse has occured
   if (aState != aLastState){     
     // If the outputB state is different to the outputA state, that means the encoder is rotating clockwise
     if (digitalRead(outputB) != aState) { 
       counter ++;
     } else {
       counter --;
     }
     Serial.print("Position: ");
     Serial.println(counter);
   } 
   aLastState = aState; // Updates the previous state of the outputA with the current state
 }

Wróć do „Arduino impulsator”