User Tools

Site Tools


raspberrypi:pigpio_rencoder.c

This is an old revision of the document!


sis kodas labai gerai ir tiklsiai veikia

kazkodel su python sito pasiekti nepavyksta

#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
 
#include <termios.h> 
#include <unistd.h>  
 
#include <pigpio.h>
 
/*
gcc -Wall -pthread -o pigpio_rencoder pigpio_rencoder.c -lpigpio -O3
sudo ./pigpio_rencoder
*/
 
int pin1 = 16;
int pin2 = 12;
int pin3 = 20;
 
int previous_pin = 0;
int previous_level = 0;
int p = 0;
 
void aFunction(int gpio, int level, uint32_t tick)
{
   if (gpio == pin2 && previous_pin == pin1 && level == 0 && previous_level == 0) p--;
   if (gpio == pin1 && previous_pin == pin2 && level == 0 && previous_level == 0) p++;
   printf("GPIO %3d became %3d at %10d, value = %5d\n", gpio, level, tick, p);
   previous_pin = gpio;
   previous_level = level;
}
 
int main(int argc, char *argv[])
{
    /*static struct termios oldt, newt;
    tcgetattr( STDIN_FILENO, &oldt);
    newt = oldt;
    newt.c_lflag &= ~(ICANON | ECHO);          
    tcsetattr( STDIN_FILENO, TCSANOW, &newt);*/
 
   if (gpioInitialise() < 0) return -1;
 
   //int p = 0;
   gpioSetAlertFunc(pin1, aFunction);
   gpioSetAlertFunc(pin2, aFunction);
   gpioSetAlertFunc(pin3, aFunction);
 
    printf("Press e to exit program\n");
    //printf("press q and w to increase and decrease software pwm\n");
    int c;  
    while((c=getchar())!= 'e')
    {      
        //if (c == 'q') p +=5;
        //if (c == 'w') p -=5;
        //printf("%3d   \r",p);
        //gpioServo(18, p);
        sleep(10);
    } 
 
   //tcsetattr( STDIN_FILENO, TCSANOW, &oldt);
   return 0;   
}
raspberrypi/pigpio_rencoder.c.1494160953.txt.gz · Last modified: by aistis