Skip to content
Extraits de code Groupes Projets
dieg.cpp 1,29 ko
Newer Older
  • Learn to ignore specific revisions
  • #include <wiringPi.h>
    #include <wiringPiSPI.h>
    
    #include <stdio.h>
    #include <unistd.h>
    #include <stdlib.h>
    
    #include <conio.h>
    
    const int PWM_PIN_RIGHT = 23;
    const int M1DIR_RIGHT   = 21;
    const int PWM_PIN_LEFT  = 26;
    const int M2DIR_LEFT    = 22;
    
    int main(int argc, char const *argv[])
    {
        if (wiringPiSetup() == -1) {
            printf("WiringPiSetup failed\n");
            exit(EXIT_FAILURE);
        }
    
        pinMode(PWM_PIN_RIGHT, PWM_OUTPUT);
        pinMode(PWM_PIN_LEFT, PWM_OUTPUT);
        pinMode(M1DIR_RIGHT, OUTPUT);
        pinMode(M2DIR_LEFT, OUTPUT);
    
        digitalWrite(M1DIR_RIGHT, 1);
    
        int fd;
    
        fd = wiringPiSPISetup(1, 1000000);
    
        unsigned char buffer [4];
    
        buffer[0] = 0x00;
        buffer[1] = 0x00;
        buffer[2] = 0x00;
        buffer[3] = 0x00;
    
        wiringPiSPIDataRW(1, buffer, 4);
    
        sleep(1);
    
        buffer[0] = 0x00;
        buffer[1] = 0x00;
        buffer[2] = 0x00;
        buffer[3] = 0x01;
    
        wiringPiSPIDataRW(1, buffer, 4);
    
        pwmWrite(PWM_PIN_RIGHT, 560);
    
        while (1)
        {
            if (kbhit()) goto end;
            buffer[0] = 0x00;
            buffer[1] = 0x00;
            buffer[2] = 0x00;
            buffer[3] = 0x01;
            wiringPiSPIDataRW(1,buffer, 4);
            printf("%x %x %x %x\n", buffer[0],buffer[1],buffer[2],buffer[3]);
            sleep(1); 
        }
    
    end:
        pwmWrite(PWM_PIN_RIGHT, 0);
        return 0;
    }