-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
68 lines (49 loc) · 1.05 KB
/
main.c
File metadata and controls
68 lines (49 loc) · 1.05 KB
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 "general.h"
#include "chip.h"
#include "i2c.h"
#include "pca9685.h"
/* System oscillator rate and clock rate on the CLKIN pin */
const uint32_t OscRateIn = 12000000;
const uint32_t ExtRateIn = 0;
volatile float dc = 1;
float add = 0.5;
void SysTick_Handler()
{
if(dc >= 100 || dc <= 0)
{
add = add * -1;
}
PCA9685_SetPWM(0, 0, dc / 100.0);
PCA9685_SetPWM(1, 0, 1 - dc / 100.0);
PCA9685_SetPWM(2, 0, 1 - 2 * dc / 100.0);
dc += add;
}
int main()
{
SystemCoreClockUpdate();
Chip_GPIO_Init(LPC_GPIO);
Chip_GPIO_SetPinDIROutput(LPC_GPIO, 1, 10);
Chip_GPIO_SetPinDIROutput(LPC_GPIO, 1, 11);
SysTick_Config(SystemCoreClock / 100);
I2C_Init();
PCA9685_SetAddress(0x40);
if(PCA9685_Init() == NO_ERROR)
{
if(PCA9685_SetPWM(0, 0, 0.5) == NO_ERROR)
{
Chip_GPIO_SetPinState(LPC_GPIO, 1, 11, false);
}
else
{
Chip_GPIO_SetPinState(LPC_GPIO, 1, 10, false);
}
}
else
{
Chip_GPIO_SetPinState(LPC_GPIO, 1, 10, false);
}
while(1)
{
PCA9685_Idle();
}
}