Added software PWM module into wiringPi - library code
and an example.
This commit is contained in:
@@ -35,11 +35,11 @@ LIBS = -lwiringPi
|
||||
# Should not alter anything below this line
|
||||
###############################################################################
|
||||
|
||||
SRC = test1.c test2.c speed.c lcd.c wfi.c piface.c gertboard.c nes.c delayTest.c
|
||||
SRC = test1.c test2.c speed.c lcd.c wfi.c piface.c gertboard.c nes.c delayTest.c softPwm.c
|
||||
|
||||
OBJ = test1.o test2.o speed.o lcd.o wfi.o piface.o gertboard.o nes.o delayTest.o
|
||||
OBJ = test1.o test2.o speed.o lcd.o wfi.o piface.o gertboard.o nes.o delayTest.o softPwm.o
|
||||
|
||||
all: test1 test2 speed lcd wfi piface gertboard nes
|
||||
all: test1 test2 speed lcd wfi piface gertboard nes softPwm
|
||||
|
||||
test1: test1.o
|
||||
@echo [link]
|
||||
@@ -73,6 +73,10 @@ nes: nes.o
|
||||
@echo [link]
|
||||
$(CC) -o $@ nes.o $(LDFLAGS) $(LIBS) -lm
|
||||
|
||||
softPwm: softPwm.o
|
||||
@echo [link]
|
||||
$(CC) -o $@ softPwm.o $(LDFLAGS) $(LIBS) -lm -lpthread
|
||||
|
||||
|
||||
delayTest: delayTest.o
|
||||
@echo [link]
|
||||
@@ -84,7 +88,7 @@ delayTest: delayTest.o
|
||||
@$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
clean:
|
||||
rm -f $(OBJ) *~ core tags test1 test2 speed lcd wfi piface gertboard nes delayTest
|
||||
rm -f $(OBJ) *~ core tags test1 test2 speed lcd wfi piface gertboard nes delayTest softPwm
|
||||
|
||||
tags: $(SRC)
|
||||
@echo [ctags]
|
||||
|
||||
44
examples/softPwm.c
Normal file
44
examples/softPwm.c
Normal file
@@ -0,0 +1,44 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <wiringPi.h>
|
||||
#include <softPwm.h>
|
||||
|
||||
#define RANGE 100
|
||||
#define NUM_LEDS 12
|
||||
|
||||
int ledMap [NUM_LEDS] = { 0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13 } ;
|
||||
|
||||
int values [NUM_LEDS] = { 0, 17, 32, 50, 67, 85, 100, 85, 67, 50, 32, 17 } ;
|
||||
|
||||
int main ()
|
||||
{
|
||||
int i, j ;
|
||||
|
||||
if (wiringPiSetup () == -1)
|
||||
{
|
||||
fprintf (stdout, "oops: %s\n", strerror (errno)) ;
|
||||
return 1 ;
|
||||
}
|
||||
|
||||
for (i = 0 ; i < NUM_LEDS ; ++i)
|
||||
{
|
||||
softPwmCreate (ledMap [i], 0, RANGE) ;
|
||||
printf ("%3d, %3d, %3d\n", i, ledMap [i], values [i]) ;
|
||||
}
|
||||
|
||||
for (;;)
|
||||
{
|
||||
for (i = 0 ; i < NUM_LEDS ; ++i)
|
||||
softPwmWrite (ledMap [i], values [i]) ;
|
||||
|
||||
delay (50) ;
|
||||
|
||||
i = values [0] ;
|
||||
for (j = 0 ; j < NUM_LEDS - 1 ; ++j)
|
||||
values [j] = values [j + 1] ;
|
||||
values [NUM_LEDS - 1] = i ;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user