-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
90 lines (72 loc) · 1.87 KB
/
main.c
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <stdio.h>
#include <stdlib.h>
//#include <iostream.h>
#include <string.h>
#include <unistd.h>
#include "gpio.h"
#include "pwm.h"
unsigned int M1EN; // Enable
unsigned int M1NA; // Direction
unsigned int M1NB; // Direction
unsigned int M1CS; // Current sense
int main(int argc, char *argv[]){
int i;
printf("Testing the GPIO Pins\n");
M1EN = gpio_no(0,30); // P9-11
M1NA = gpio_no(1,28); // P9-12
M1NB = gpio_no(0,31); // P9-13
M1CS = gpio_no(1,19); // P9-15
// echo n > export
gpio_export(M1EN);
gpio_export(M1NA);
gpio_export(M1NB);
gpio_export(M1CS);
// Set Direction, echo in/out > direction
gpio_set_dir(M1EN, OUTPUT_PIN);
gpio_set_dir(M1NA, OUTPUT_PIN);
gpio_set_dir(M1NB, OUTPUT_PIN);
gpio_set_dir(M1CS, INPUT_PIN);
// echo 1/0 > value
gpio_set_value(M1EN, LOW);
gpio_set_value(M1NA, LOW);
gpio_set_value(M1NB, LOW);
gpio_set_value(M1CS, LOW);
// Setup PWM
pwm_set_enable(0);
pwm_set_period(5000000);
pwm_set_duty(1000000);
pwm_set_polarity(1);
// Start
pwm_set_enable(1);
// Flash the LED 5 times
for(i=0; i<100; i++){
printf("Setting the M1EN on\n");
gpio_set_value(M1EN, HIGH);
gpio_set_value(M1NA, HIGH);
gpio_set_value(M1NB, HIGH);
gpio_set_value(M1CS, HIGH);
usleep(200000); // on for 200ms
printf("Setting the M1EN off\n");
gpio_set_value(M1EN, LOW);
gpio_set_value(M1NA, LOW);
gpio_set_value(M1NB, LOW);
gpio_set_value(M1CS, LOW);
usleep(200000); // off for 200ms
}
/*
unsigned int value = LOW;
do {
gpio_get_value(ButtonGPIO, &value);
printf(".");
usleep(1000); // sleep for one millisecond
} while (value!=HIGH);
printf("\nButton was just pressed!\n");
*/
printf("Finished Testing the GPIO Pins\n");
gpio_unexport(M1EN);
gpio_unexport(M1NA);
gpio_unexport(M1NB);
gpio_unexport(M1CS);
pwm_set_enable(0);
return 0;
}