mirror of
https://github.com/clockworkpi/WiringPi.git
synced 2026-03-21 03:12:47 +01:00
Initial Commit
This commit is contained in:
71
examples/Makefile
Normal file
71
examples/Makefile
Normal file
@@ -0,0 +1,71 @@
|
||||
#
|
||||
# Makefile:
|
||||
# wiringPi - Wiring Compatable library for the Raspberry Pi
|
||||
# https://projects.drogon.net/wiring-pi
|
||||
#
|
||||
# Copyright (c) 2012 Gordon Henderson
|
||||
#################################################################################
|
||||
# This file is part of wiringPi:
|
||||
# Wiring Compatable library for the Raspberry Pi
|
||||
#
|
||||
# wiringPi is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# wiringPi is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
||||
#################################################################################
|
||||
|
||||
|
||||
#DEBUG = -g -O0
|
||||
DEBUG = -O3
|
||||
CC = gcc
|
||||
INCLUDE = -I/usr/local/include
|
||||
CFLAGS = $(DEBUG) -Wall $(INCLUDE) -Winline -pipe
|
||||
|
||||
LDFLAGS = -L/usr/local/lib
|
||||
LIBS = -lwiringPi
|
||||
|
||||
# Should not alter anything below this line
|
||||
###############################################################################
|
||||
|
||||
SRC = test1.c test2.c speed.c
|
||||
|
||||
OBJ = test1.o test2.o speed.o
|
||||
|
||||
all: test1 test2 speed
|
||||
|
||||
test1: test1.o
|
||||
@echo [link]
|
||||
$(CC) -o $@ test1.o $(LDFLAGS) $(LIBS)
|
||||
|
||||
test2: test2.o
|
||||
@echo [link]
|
||||
$(CC) -o $@ test2.o $(LDFLAGS) $(LIBS)
|
||||
|
||||
speed: speed.o
|
||||
@echo [link]
|
||||
$(CC) -o $@ speed.o $(LDFLAGS) $(LIBS)
|
||||
|
||||
|
||||
.c.o:
|
||||
@echo [CC] $<
|
||||
@$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
clean:
|
||||
rm -f $(OBJ) *~ core tags test1 test2 speed
|
||||
|
||||
tags: $(SRC)
|
||||
@echo [ctags]
|
||||
@ctags $(SRC)
|
||||
|
||||
depend:
|
||||
makedepend -Y $(SRC)
|
||||
|
||||
# DO NOT DELETE
|
||||
103
examples/speed.c
Normal file
103
examples/speed.c
Normal file
@@ -0,0 +1,103 @@
|
||||
|
||||
/*
|
||||
* speed.c:
|
||||
* Simple program to measure the speed of the various GPIO
|
||||
* access mechanisms.
|
||||
*/
|
||||
|
||||
#include <wiringPi.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define FAST_COUNT 10000000
|
||||
#define SLOW_COUNT 1000000
|
||||
|
||||
|
||||
int main (void)
|
||||
{
|
||||
int i ;
|
||||
uint32_t start, end, count, sum, perSec ;
|
||||
|
||||
printf ("Raspberry Pi wiringPi speed test program\n") ;
|
||||
|
||||
// Start the standard way
|
||||
|
||||
if (wiringPiSetup () == -1)
|
||||
exit (1) ;
|
||||
|
||||
printf ("Native wiringPi method: (%8d iterations)\n", FAST_COUNT) ;
|
||||
|
||||
pinMode (0, OUTPUT) ;
|
||||
|
||||
sum = 0 ;
|
||||
for (i = 0 ; i < 3 ; ++i)
|
||||
{
|
||||
printf (" Pass: %d: ", i) ;
|
||||
fflush (stdout) ;
|
||||
|
||||
start = millis () ;
|
||||
for (count = 0 ; count < FAST_COUNT ; ++count)
|
||||
digitalWrite (0, 1) ;
|
||||
end = millis () ;
|
||||
printf (" %8dmS\n", end - start) ;
|
||||
sum += (end - start) ;
|
||||
}
|
||||
digitalWrite (0, 0) ;
|
||||
printf (" Average: %8dmS", sum / 3) ;
|
||||
perSec = (int)(double)FAST_COUNT / (double)((double)sum / 3.0) * 1000.0 ;
|
||||
printf (": %6d/sec\n", perSec) ;
|
||||
|
||||
|
||||
printf ("Native GPIO method: (%8d iterations)\n", FAST_COUNT) ;
|
||||
|
||||
wiringPiGpioMode (WPI_MODE_GPIO) ;
|
||||
|
||||
pinMode (17, OUTPUT) ;
|
||||
|
||||
sum = 0 ;
|
||||
for (i = 0 ; i < 3 ; ++i)
|
||||
{
|
||||
printf (" Pass: %d: ", i) ;
|
||||
fflush (stdout) ;
|
||||
|
||||
start = millis () ;
|
||||
for (count = 0 ; count < 10000000 ; ++count)
|
||||
digitalWrite (17, 1) ;
|
||||
end = millis () ;
|
||||
printf (" %8dmS\n", end - start) ;
|
||||
sum += (end - start) ;
|
||||
}
|
||||
digitalWrite (17, 0) ;
|
||||
printf (" Average: %8dmS", sum / 3) ;
|
||||
perSec = (int)(double)FAST_COUNT / (double)((double)sum / 3.0) * 1000.0 ;
|
||||
printf (": %6d/sec\n", perSec) ;
|
||||
|
||||
|
||||
// Switch to SYS mode:
|
||||
|
||||
wiringPiSetupSys () ;
|
||||
|
||||
printf ("/sys/class/gpio method: (%8d iterations)\n", SLOW_COUNT) ;
|
||||
|
||||
sum = 0 ;
|
||||
for (i = 0 ; i < 3 ; ++i)
|
||||
{
|
||||
printf (" Pass: %d: ", i) ;
|
||||
fflush (stdout) ;
|
||||
|
||||
start = millis () ;
|
||||
for (count = 0 ; count < SLOW_COUNT ; ++count)
|
||||
digitalWrite (17, 1) ;
|
||||
end = millis () ;
|
||||
printf (" %8dmS\n", end - start) ;
|
||||
sum += (end - start) ;
|
||||
}
|
||||
digitalWrite (17, 0) ;
|
||||
printf (" Average: %8dmS", sum / 3) ;
|
||||
perSec = (int)(double)SLOW_COUNT / (double)((double)sum / 3.0) * 1000.0 ;
|
||||
printf (": %6d/sec\n", perSec) ;
|
||||
|
||||
return 0 ;
|
||||
}
|
||||
BIN
examples/test1
Executable file
BIN
examples/test1
Executable file
Binary file not shown.
91
examples/test1.c
Normal file
91
examples/test1.c
Normal file
@@ -0,0 +1,91 @@
|
||||
|
||||
/*
|
||||
* test1.c:
|
||||
* Simple test program to test the wiringPi functions
|
||||
*/
|
||||
|
||||
#include <wiringPi.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
// Simple sequencer data
|
||||
// Triplets of LED, On/Off and delay
|
||||
|
||||
uint8_t data [] =
|
||||
{
|
||||
0, 1, 1,
|
||||
1, 1, 1,
|
||||
0, 0, 0, 2, 1, 1,
|
||||
1, 0, 0, 3, 1, 1,
|
||||
2, 0, 0, 4, 1, 1,
|
||||
3, 0, 0, 5, 1, 1,
|
||||
4, 0, 0, 6, 1, 1,
|
||||
5, 0, 0, 7, 1, 1,
|
||||
6, 0, 1,
|
||||
7, 0, 1,
|
||||
|
||||
0, 0, 1, // Extra delay
|
||||
|
||||
// Back again
|
||||
|
||||
7, 1, 1,
|
||||
6, 1, 1,
|
||||
7, 0, 0, 5, 1, 1,
|
||||
6, 0, 0, 4, 1, 1,
|
||||
5, 0, 0, 3, 1, 1,
|
||||
4, 0, 0, 2, 1, 1,
|
||||
3, 0, 0, 1, 1, 1,
|
||||
2, 0, 0, 0, 1, 1,
|
||||
1, 0, 1,
|
||||
0, 0, 1,
|
||||
|
||||
0, 0, 1, // Extra delay
|
||||
|
||||
9, 9, 9, // End marker
|
||||
|
||||
} ;
|
||||
|
||||
|
||||
int main (void)
|
||||
{
|
||||
int pin ;
|
||||
int dataPtr ;
|
||||
int l, s, d ;
|
||||
|
||||
printf ("Raspberry Pi wiringPi test program\n") ;
|
||||
|
||||
if (wiringPiSetup () == -1)
|
||||
exit (1) ;
|
||||
|
||||
for (pin = 0 ; pin < 8 ; ++pin)
|
||||
pinMode (pin, OUTPUT) ;
|
||||
|
||||
pinMode (8, INPUT) ; // Pin 8 SDA0 - Has on-board 2k2 pull-up resistor
|
||||
|
||||
dataPtr = 0 ;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
l = data [dataPtr++] ; // LED
|
||||
s = data [dataPtr++] ; // State
|
||||
d = data [dataPtr++] ; // Duration (10ths)
|
||||
|
||||
if ((l + s + d) == 27)
|
||||
{
|
||||
dataPtr = 0 ;
|
||||
continue ;
|
||||
}
|
||||
|
||||
digitalWrite (l, s) ;
|
||||
|
||||
if (digitalRead (8) == 0) // Pressed as our switch shorts to ground
|
||||
delay (d * 10) ; // Faster!
|
||||
else
|
||||
delay (d * 100) ;
|
||||
}
|
||||
|
||||
return 0 ;
|
||||
}
|
||||
BIN
examples/test2
Executable file
BIN
examples/test2
Executable file
Binary file not shown.
41
examples/test2.c
Normal file
41
examples/test2.c
Normal file
@@ -0,0 +1,41 @@
|
||||
|
||||
/*
|
||||
* test2.c:
|
||||
* Simple test program to test the wiringPi functions
|
||||
* PWM test
|
||||
*/
|
||||
|
||||
#include <wiringPi.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
int main (void)
|
||||
{
|
||||
int bright ;
|
||||
|
||||
printf ("Raspberry Pi wiringPi PWM test program\n") ;
|
||||
|
||||
if (wiringPiSetup () == -1)
|
||||
exit (1) ;
|
||||
|
||||
pinMode (1, PWM_OUTPUT) ;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
for (bright = 0 ; bright < 1024 ; ++bright)
|
||||
{
|
||||
pwmWrite (1, bright) ;
|
||||
delay (1) ;
|
||||
}
|
||||
|
||||
for (bright = 1023 ; bright >= 0 ; --bright)
|
||||
{
|
||||
pwmWrite (1, bright) ;
|
||||
delay (1) ;
|
||||
}
|
||||
}
|
||||
|
||||
return 0 ;
|
||||
}
|
||||
Reference in New Issue
Block a user