Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#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;
}