06-03-2019, 20:41
Witam
Mam taki problem, a mianowicie po uruchomieniu programu (pobrany z sieci) kręcąc czy to w lewo lub prawo enkoderem program liczy tylko w jedną stronę, jest to sam enkoder dodaje rezystory 10k z vcc na sygnał, próbowałem bez, oraz kondensatory po 100nF i ciągle to samo, enkodery też mam 2
Mam taki problem, a mianowicie po uruchomieniu programu (pobrany z sieci) kręcąc czy to w lewo lub prawo enkoderem program liczy tylko w jedną stronę, jest to sam enkoder dodaje rezystory 10k z vcc na sygnał, próbowałem bez, oraz kondensatory po 100nF i ciągle to samo, enkodery też mam 2
Kod:
#define PinA 2
#define PinB 3
#define PinP 19
int nacisnieto=0;
unsigned long time = 0;
long count = 0;
long num = 0;
void setup()
{
Serial.begin(9600);
pinMode(PinA,INPUT);
pinMode(PinB,INPUT);
pinMode(PinP,INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(3), blinkA, LOW);
attachInterrupt(digitalPinToInterrupt(2), blinkB, LOW);
time = millis();
}
void loop()
{
przycisk();
if(nacisnieto==1){
Serial.println("wcisnieto");
nacisnieto=0;
}
while (num != count)
{
num = count;
Serial.println(num);
}
}
void blinkA()
{
if ((millis() - time) > 3)
count ++;
time = millis();
}
void blinkB()
{
if ((millis() - time) > 3)
count --;
time = millis();
}
void przycisk(){
if (digitalRead(18)==LOW){
if ((millis() - time) > 500){
nacisnieto=1;
time = millis();
}
}
}