-
Notifications
You must be signed in to change notification settings - Fork 1
/
pwmlauncher.c
57 lines (49 loc) · 1.38 KB
/
pwmlauncher.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
#include <wiringPi.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#define PWCLKDIVIDER 2400
#define PWRANGE 4000
#define GPIOPINPWM 13//20//13 //13 is software PWM, 18 is hardware PWM but already used
/*****************************************
* WiringPi launcher to set PWM *
* based on James Ward PWM settings *
* to work with SSR and Espresso machine *
*****************************************/
int main (int argc, char *argv[])
{
int drive = 0;
int doinit = 0;
if(argc != 3)
{
printf("Error: invalid arguments. Usage: sudo pwmlauncher <a> <bbb> where a is init (1 or 0) and bbb the drive percent\n");
exit(0);
}
printf("bye bye\n");
exit(0);
//printf ("Welcome into PWM drive launcher\n") ;
//retrieve init argument
doinit = atoi(argv[1]);
//retrieve drive argument
drive = atoi(argv[2]);
if(drive > 100)
drive = 100;
printf("boiler drive=%d%\n",drive);
//init wiringpi
if (wiringPiSetupGpio() == -1){
printf("Error inint wiringpi lib\n");
exit (1) ;
}
if(doinit){
printf("init pwm boiler\n");
//PWM mode
pinMode(GPIOPINPWM,PWM_OUTPUT);
//PWM "predictive mode"
pwmSetMode(PWM_MODE_MS);
//set clock at 2Hz (clock divider / range)
pwmSetClock(PWCLKDIVIDER);
pwmSetRange (PWRANGE) ;
}
//setting drive according to the RANGE
pwmWrite (GPIOPINPWM, (drive * (PWRANGE / 100)));
}