WiringPi V2.0 for Python2 & Python3

This commit is contained in:
Philip Howard
2013-03-27 22:22:00 +00:00
parent 98bcb20d93
commit 567ee0027e
89 changed files with 10178 additions and 1302 deletions

View File

@@ -1,165 +0,0 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.

View File

@@ -1,141 +0,0 @@
#
# 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 Lesser 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser 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
LDLIBS = -lwiringPi -lpthread -lm
# Should not alter anything below this line
###############################################################################
SRC = blink.c test1.c test2.c speed.c lcd.c wfi.c isr.c isr-osc.c \
piface.c gertboard.c nes.c \
pwm.c tone.c servo.c \
delayTest.c serialRead.c serialTest.c okLed.c
OBJ = $(SRC:.c=.o)
BINS = $(SRC:.c=)
all:
@cat README.TXT
@echo " $(BINS)" | fmt
@echo ""
really-all: $(BINS)
blink: blink.o
@echo [link]
@$(CC) -o $@ blink.o $(LDFLAGS) $(LDLIBS)
test1: test1.o
@echo [link]
@$(CC) -o $@ test1.o $(LDFLAGS) $(LDLIBS)
test2: test2.o
@echo [link]
@$(CC) -o $@ test2.o $(LDFLAGS) $(LDLIBS)
speed: speed.o
@echo [link]
@$(CC) -o $@ speed.o $(LDFLAGS) $(LDLIBS)
lcd: lcd.o
@echo [link]
@$(CC) -o $@ lcd.o $(LDFLAGS) $(LDLIBS)
wfi: wfi.o
@echo [link]
@$(CC) -o $@ wfi.o $(LDFLAGS) $(LDLIBS)
isr: isr.o
@echo [link]
@$(CC) -o $@ isr.o $(LDFLAGS) $(LDLIBS)
isr-osc: isr-osc.o
@echo [link]
@$(CC) -o $@ isr-osc.o $(LDFLAGS) $(LDLIBS)
piface: piface.o
@echo [link]
@$(CC) -o $@ piface.o $(LDFLAGS) $(LDLIBS)
gertboard: gertboard.o
@echo [link]
@$(CC) -o $@ gertboard.o $(LDFLAGS) $(LDLIBS)
nes: nes.o
@echo [link]
@$(CC) -o $@ nes.o $(LDFLAGS) $(LDLIBS)
pwm: pwm.o
@echo [link]
@$(CC) -o $@ pwm.o $(LDFLAGS) $(LDLIBS)
delayTest: delayTest.o
@echo [link]
@$(CC) -o $@ delayTest.o $(LDFLAGS) $(LDLIBS)
serialRead: serialRead.o
@echo [link]
@$(CC) -o $@ serialRead.o $(LDFLAGS) $(LDLIBS)
serialTest: serialTest.o
@echo [link]
@$(CC) -o $@ serialTest.o $(LDFLAGS) $(LDLIBS)
okLed: okLed.o
@echo [link]
@$(CC) -o $@ okLed.o $(LDFLAGS) $(LDLIBS)
tone: tone.o
@echo [link]
@$(CC) -o $@ tone.o $(LDFLAGS) $(LDLIBS)
servo: servo.o
@echo [link]
@$(CC) -o $@ servo.o $(LDFLAGS) $(LDLIBS)
.c.o:
@echo [CC] $<
@$(CC) -c $(CFLAGS) $< -o $@
clean:
rm -f $(OBJ) *~ core tags $(BINS)
tags: $(SRC)
@echo [ctags]
@ctags $(SRC)
depend:
makedepend -Y $(SRC)
# DO NOT DELETE

View File

@@ -1,18 +0,0 @@
wiringPi Examples
=================
There are now too many examples to compile them all in a sensible time,
and you probably don't want to compile or run them all anyway, so they
have been separated out.
To compile an individual example, just type
make exampleName
To really compile everything:
make really-all
The individual tests are:

View File

@@ -1,50 +0,0 @@
/*
* blink.c:
* Standard "blink" program in wiringPi. Blinks an LED connected
* to the first GPIO pin.
*
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <wiringPi.h>
// LED Pin - wiringPi pin 0 is BCM_GPIO 17.
#define LED 0
int main (void)
{
printf ("Raspberry Pi blink\n") ;
if (wiringPiSetup () == -1)
return 1 ;
pinMode (LED, OUTPUT) ;
for (;;)
{
digitalWrite (LED, 1) ; // On
delay (500) ; // mS
digitalWrite (LED, 0) ; // Off
delay (500) ;
}
return 0 ;
}

View File

@@ -1,30 +0,0 @@
// blink.rtb:
// Blink program in Return to Basic
//
// Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
//**********************************************************************
// This file is part of wiringPi:
// https://projects.drogon.net/raspberry-pi/wiringpi/
//
// wiringPi is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
//
PinMode (0, 1) // Output
CYCLE
DigitalWrite (0, 1) // Pin 0 ON
WAIT (0.5) // 0.5 seconds
DigitalWrite (0, 0)
WAIT (0.5)
REPEAT
END

View File

@@ -1,37 +0,0 @@
#!/bin/sh
#
# blink.sh:
# Standard "blink" program in wiringPi. Blinks an LED connected
# to the first GPIO pin.
#
# Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
#######################################################################
# This file is part of wiringPi:
# https://projects.drogon.net/raspberry-pi/wiringpi/
#
# wiringPi is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
#######################################################################
# LED Pin - wiringPi pin 0 is BCM_GPIO 17.
LED=0
gpio mode $PIN out
while true; do
gpio write $PIN 1
sleep 0.5
gpio write $PIN 0
sleep 0.5
done

View File

@@ -1,107 +0,0 @@
/*
* delayTest.c:
* Just a little test program I'm using to experiment with
* various timings and latency, etc.
*
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <unistd.h>
#include <wiringPi.h>
#include <sys/time.h>
#define CYCLES 1000
int main()
{
int x ;
struct timeval t1, t2 ;
int t ;
int max, min ;
int del ;
int underRuns, overRuns, exactRuns, total ;
int descheds ;
if (wiringPiSetup () == -1)
return 1 ;
piHiPri (10) ; sleep (1) ;
// Baseline test
gettimeofday (&t1, NULL) ;
gettimeofday (&t2, NULL) ;
t = t2.tv_usec - t1.tv_usec ;
printf ("Baseline test: %d\n", t);
for (del = 1 ; del < 200 ; ++del)
{
underRuns = overRuns = exactRuns = total = 0 ;
descheds = 0 ;
max = del ;
min = del ;
for (x = 0 ; x < CYCLES ; ++x)
{
for (;;) // Repeat this if we get a delay over 999uS
{ // -> High probability Linux has deschedulled us
gettimeofday (&t1, NULL) ;
delayMicroseconds (del) ;
gettimeofday (&t2, NULL) ;
if (t2.tv_usec < t1.tv_usec) // Counter wrapped
t = (1000000 + t2.tv_usec) - t1.tv_usec;
else
t = t2.tv_usec - t1.tv_usec ;
if (t > 999)
{
++descheds ;
continue ;
}
else
break ;
}
if (t > max)
{
max = t ;
++overRuns ;
}
else if (t < min)
{
min = t ;
++underRuns ;
}
else
++exactRuns ;
total += t ;
}
printf ("Delay: %3d. Min: %3d, Max: %3d, Unders: %3d, Overs: %3d, Exacts: %3d, Average: %3d, Descheds: %2d\n",
del, min, max, underRuns, overRuns, exactRuns, total / CYCLES, descheds) ;
fflush (stdout) ;
delay (1) ;
}
return 0 ;
}

View File

@@ -1,94 +0,0 @@
/*
* gertboard.c:
* Simple test for the SPI bus on the Gertboard
*
* Hardware setup:
* D/A port 0 jumpered to A/D port 0.
*
* We output a sine wave on D/A port 0 and sample A/D port 0. We then
* copy this value to D/A port 1 and use a 'scope on both D/A ports
* to check all's well.
*
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <stdint.h>
#include <math.h>
#define B_SIZE 200
#undef DO_TIMING
#include <wiringPi.h>
#include <gertboard.h>
int main (void)
{
double angle ;
int i ;
uint32_t x1 ;
int buffer [B_SIZE] ;
#ifdef DO_TIMING
unsigned int now, then ;
#endif
printf ("Raspberry Pi Gertboard SPI test program\n") ;
if (wiringPiSetupSys () < 0)
return -1 ;
if (gertboardSPISetup () < 0)
return 1 ;
// Generate a Sine Wave
for (i = 0 ; i < B_SIZE ; ++i)
{
angle = ((double)i / (double)B_SIZE) * M_PI * 2.0 ;
buffer [i] = (int)rint ((sin (angle)) * 127.0 + 128.0) ;
}
for (;;)
{
#ifdef DO_TIMING
then = millis () ;
#endif
for (i = 0 ; i < B_SIZE ; ++i)
{
gertboardAnalogWrite (0, buffer [i]) ;
#ifndef DO_TIMING
x1 = gertboardAnalogRead (0) ;
gertboardAnalogWrite (1, x1 >> 2) ; // 10-bit A/D, 8-bit D/A
#endif
}
#ifdef DO_TIMING
now = millis () ;
printf ("%4d mS, %9.7f S/sample", now - then, ((double)(now - then) / 1000.0) / (double)B_SIZE) ;
printf (" -> %9.4f samples/sec \n", 1 / (((double)(now - then) / 1000.0) / (double)B_SIZE)) ;
#endif
}
return 0 ;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

View File

@@ -1,23 +0,0 @@
/*
* file.c:
*
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/

View File

@@ -1,118 +0,0 @@
/*
* isr-osc.c:
* Wait for Interrupt test program - ISR method - interrupt oscillator
*
* How to test:
*
* IMPORTANT: To run this test we connect 2 GPIO pins together, but
* before we do that YOU must make sure that they are both setup
* the right way. If they are set to outputs and one is high and one low,
* then you connect the wire, you'll create a short and that won't be good.
*
* Before making the connection, type:
* gpio mode 0 output
* gpio write 0 0
* gpio mode 1 input
* then you can connect them together.
*
* Run the program, then:
* gpio write 0 1
* gpio write 0 0
*
* at which point it will trigger an interrupt and the program will
* then do the up/down toggling for itself and run at full speed, and
* it will report the number of interrupts recieved every second.
*
* Copyright (c) 2013 Gordon Henderson. projects@drogon.net
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <wiringPi.h>
// What GPIO input are we using?
// This is a wiringPi pin number
#define OUT_PIN 0
#define IN_PIN 1
// globalCounter:
// Global variable to count interrupts
// Should be declared volatile to make sure the compiler doesn't cache it.
static volatile int globalCounter = 0 ;
/*
* myInterrupt:
*********************************************************************************
*/
void myInterrupt (void)
{
digitalWrite (OUT_PIN, 1) ;
++globalCounter ;
digitalWrite (OUT_PIN, 0) ;
}
/*
*********************************************************************************
* main
*********************************************************************************
*/
int main (void)
{
int myCounter = 0 ;
int lastCounter = 0 ;
if (wiringPiSetup () < 0)
{
fprintf (stderr, "Unable to setup wiringPi: %s\n", strerror (errno)) ;
return 1 ;
}
pinMode (OUT_PIN, OUTPUT) ;
pinMode (IN_PIN, INPUT) ;
if (wiringPiISR (IN_PIN, INT_EDGE_FALLING, &myInterrupt) < 0)
{
fprintf (stderr, "Unable to setup ISR: %s\n", strerror (errno)) ;
return 1 ;
}
for (;;)
{
printf ("Waiting ... ") ; fflush (stdout) ;
while (myCounter == globalCounter)
delay (1000) ;
printf (" Done. counter: %6d: %6d\n",
globalCounter, myCounter - lastCounter) ;
lastCounter = myCounter ;
myCounter = globalCounter ;
}
return 0 ;
}

View File

@@ -1,99 +0,0 @@
/*
* isr.c:
* Wait for Interrupt test program - ISR method
*
* How to test:
* Use the SoC's pull-up and pull down resistors that are avalable
* on input pins. So compile & run this program (via sudo), then
* in another terminal:
* gpio mode 0 up
* gpio mode 0 down
* at which point it should trigger an interrupt. Toggle the pin
* up/down to generate more interrupts to test.
*
* Copyright (c) 2013 Gordon Henderson.
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <wiringPi.h>
// What GPIO input are we using?
// This is a wiringPi pin number
#define BUTTON_PIN 0
// globalCounter:
// Global variable to count interrupts
// Should be declared volatile to make sure the compiler doesn't cache it.
static volatile int globalCounter = 0 ;
/*
* myInterrupt:
*********************************************************************************
*/
void myInterrupt (void)
{
++globalCounter ;
}
/*
*********************************************************************************
* main
*********************************************************************************
*/
int main (void)
{
int myCounter = 0 ;
if (wiringPiSetup () < 0)
{
fprintf (stderr, "Unable to setup wiringPi: %s\n", strerror (errno)) ;
return 1 ;
}
if (wiringPiISR (BUTTON_PIN, INT_EDGE_FALLING, &myInterrupt) < 0)
{
fprintf (stderr, "Unable to setup ISR: %s\n", strerror (errno)) ;
return 1 ;
}
for (;;)
{
printf ("Waiting ... ") ; fflush (stdout) ;
while (myCounter == globalCounter)
delay (100) ;
printf (" Done. counter: %5d\n", globalCounter) ;
myCounter = globalCounter ;
}
return 0 ;
}

View File

@@ -1,129 +0,0 @@
/*
* lcd.c:
* Text-based LCD driver.
* This is designed to drive the parallel interface LCD drivers
* based in the Hitachi HD44780U controller and compatables.
*
* Copyright (c) 2012 Gordon Henderson.
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <wiringPi.h>
#include <lcd.h>
int main (void)
{
int i, j ;
int fd1, fd2 ;
char message1 [256] ;
char message2 [256] ;
char buf1 [30] ;
char buf2 [30] ;
struct tm *t ;
time_t tim ;
printf ("Raspberry Pi LCD test program\n") ;
if (wiringPiSetup () == -1)
exit (1) ;
fd1 = lcdInit (4, 20, 4, 8, 9, 4,5,6,7,0,0,0,0) ;
fd2 = lcdInit (2, 16, 4, 8, 10, 4,5,6,7,0,0,0,0) ;
//fd1 = lcdInit (4, 20, 8, 8, 9, 0,1,2,3,4,5,6,7) ;
//fd2 = lcdInit (2, 16, 8, 8, 10, 0,1,2,3,4,5,6,7) ;
if (fd1 == -1)
{
printf ("lcdInit 1 failed\n") ;
return 1 ;
}
if (fd2 == -1)
{
printf ("lcdInit 2 failed\n") ;
return 1 ;
}
sleep (1) ;
lcdPosition (fd1, 0, 0) ; lcdPuts (fd1, " Gordon Henderson") ;
lcdPosition (fd1, 0, 1) ; lcdPuts (fd1, " --------------") ;
/*
lcdPosition (fd1, 0, 2) ; lcdPuts (fd1, " 00:00:00") ;
lcdPosition (fd1, 0, 3) ; lcdPuts (fd1, " DD:MM:YY") ;
*/
lcdPosition (fd2, 0, 0) ; lcdPuts (fd2, "Gordon Henderson") ;
lcdPosition (fd2, 0, 1) ; lcdPuts (fd2, "----------------") ;
sleep (2) ;
sprintf (message1, "%s", " http://projects.drogon.net/ ") ;
sprintf (message2, "%s", " This is a long message to go into the smaller display just for a demonstration of what we can do. ") ;
for (;;)
{
i = 0 ;
j = 0 ;
for (;;)
{
strncpy (buf1, &message1 [i], 20) ;
buf1 [20] = 0 ;
lcdPosition (fd1, 0, 1) ;
lcdPuts (fd1, buf1) ;
++i ;
if (i == strlen (message1) - 20)
i = 0 ;
strncpy (buf2, &message2 [j], 16) ;
buf2 [16] = 0 ;
lcdPosition (fd2, 0, 1) ;
lcdPuts (fd2, buf2) ;
++j ;
if (j == strlen (message2) - 16)
j = 0 ;
tim = time (NULL) ;
t = localtime (&tim) ;
sprintf (buf1, "%02d:%02d:%02d", t->tm_hour, t->tm_min, t->tm_sec) ;
lcdPosition (fd1, 5, 2) ;
lcdPuts (fd1, buf1) ;
sprintf (buf1, "%02d/%02d/%02d", t->tm_mday, t->tm_mon + 1, t->tm_year+1900) ;
lcdPosition (fd1, 4, 3) ;
lcdPuts (fd1, buf1) ;
delay (250) ;
}
}
return 0 ;
}

View File

@@ -1,67 +0,0 @@
/*
* nes.c:
* Test program for an old NES controller connected to the Pi.
*
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <wiringPi.h>
#include <piNes.h>
#define BLANK "| "
int main ()
{
int joystick ;
unsigned int buttons ;
if (wiringPiSetup () == -1)
{
fprintf (stdout, "oops: %s\n", strerror (errno)) ;
return 1 ;
}
if ((joystick = setupNesJoystick (2, 1, 0)) == -1)
{
fprintf (stdout, "Unable to setup joystick\n") ;
return 1 ;
}
for (;;)
{
buttons = readNesJoystick (joystick) ;
if ((buttons & NES_UP) != 0) printf ("| UP " ) ; else printf (BLANK) ;
if ((buttons & NES_DOWN) != 0) printf ("| DOWN " ) ; else printf (BLANK) ;
if ((buttons & NES_LEFT) != 0) printf ("| LEFT " ) ; else printf (BLANK) ;
if ((buttons & NES_RIGHT) != 0) printf ("|RIGHT " ) ; else printf (BLANK) ;
if ((buttons & NES_SELECT) != 0) printf ("|SELECT" ) ; else printf (BLANK) ;
if ((buttons & NES_START) != 0) printf ("|START " ) ; else printf (BLANK) ;
if ((buttons & NES_A) != 0) printf ("| A " ) ; else printf (BLANK) ;
if ((buttons & NES_B) != 0) printf ("| B " ) ; else printf (BLANK) ;
printf ("|\n") ;
}
return 0 ;
}

View File

@@ -1,83 +0,0 @@
/*
* okLed.c:
* Make the OK LED on the Pi Pulsate...
*
* Originally posted to the Raspberry Pi forums:
* http://www.raspberrypi.org/phpBB3/viewtopic.php?p=162581#p162581
*
* Compile this and store it somewhere, then kick it off at boot time
* e.g. by putting it in /etc/rc.local and running it in the
* background &
*
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <math.h>
#include <wiringPi.h>
#include <softPwm.h>
#define OK_LED 16
int main ()
{
int fd, i ;
if ((fd = open ("/sys/class/leds/led0/trigger", O_RDWR)) < 0)
{
fprintf (stderr, "Unable to change LED trigger: %s\n", strerror (errno)) ;
return 1 ;
}
write (fd, "none\n", 5) ;
close (fd) ;
if (wiringPiSetupGpio () < 0)
{
fprintf (stderr, "Unable to setup GPIO: %s\n", strerror (errno)) ;
return 1 ;
}
softPwmCreate (OK_LED, 0, 100) ;
for (;;)
{
for (i = 0 ; i <= 100 ; ++i)
{
softPwmWrite (OK_LED, i) ;
delay (10) ;
}
delay (50) ;
for (i = 100 ; i >= 0 ; --i)
{
softPwmWrite (OK_LED, i) ;
delay (10) ;
}
delay (10) ;
}
return 0 ;
}

View File

@@ -1,71 +0,0 @@
/*
* piFace.c:
* Simple test for the PiFace interface board.
*
* Read the buttons and output the same to the LEDs
*
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <wiringPi.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
int outputs [4] = { 0,0,0,0 } ;
void scanButton (int button)
{
if (digitalRead (button) == LOW)
{
outputs [button] ^= 1 ;
digitalWrite (button, outputs [button]) ;
}
while (digitalRead (button) == LOW)
delay (1) ;
}
int main (void)
{
int pin, button ;
printf ("Raspberry Pi wiringPiFace test program\n") ;
if (wiringPiSetupPiFace () == -1)
exit (1) ;
// Enable internal pull-ups
for (pin = 0 ; pin < 8 ; ++pin)
pullUpDnControl (pin, PUD_UP) ;
for (;;)
{
for (button = 0 ; button < 4 ; ++button)
scanButton (button) ;
delay (1) ;
}
return 0 ;
}

View File

@@ -1,93 +0,0 @@
/*
* pwm.c:
* Test of the software PWM driver. Needs 12 LEDs connected
* to the Pi.
*
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#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 ;
char buf [80] ;
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]) ;
}
fgets (buf, 80, stdin) ;
// Bring all up one by one:
for (i = 0 ; i < NUM_LEDS ; ++i)
for (j = 0 ; j <= 100 ; ++j)
{
softPwmWrite (ledMap [i], j) ;
delay (10) ;
}
fgets (buf, 80, stdin) ;
// Down fast
for (i = 100 ; i > 0 ; --i)
{
for (j = 0 ; j < NUM_LEDS ; ++j)
softPwmWrite (ledMap [j], i) ;
delay (10) ;
}
fgets (buf, 80, stdin) ;
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 ;
}
}

View File

@@ -1,48 +0,0 @@
/*
* serial.c:
* Example program to read bytes from the Serial line
*
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <wiringSerial.h>
int main ()
{
int fd ;
if ((fd = serialOpen ("/dev/ttyAMA0", 115200)) < 0)
{
fprintf (stderr, "Unable to open serial device: %s\n", strerror (errno)) ;
return 1 ;
}
// Loop, getting and printing characters
for (;;)
{
putchar (serialGetchar (fd)) ;
fflush (stdout) ;
}
}

View File

@@ -1,75 +0,0 @@
/*
* serialTest.c:
* Very simple program to test the serial port. Expects
* the port to be looped back to itself
*
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <wiringPi.h>
#include <wiringSerial.h>
int main ()
{
int fd ;
int count ;
unsigned int nextTime ;
if ((fd = serialOpen ("/dev/ttyAMA0", 115200)) < 0)
{
fprintf (stderr, "Unable to open serial device: %s\n", strerror (errno)) ;
return 1 ;
}
if (wiringPiSetup () == -1)
{
fprintf (stdout, "Unable to start wiringPi: %s\n", strerror (errno)) ;
return 1 ;
}
nextTime = millis () + 300 ;
for (count = 0 ; count < 256 ; )
{
if (millis () > nextTime)
{
printf ("\nOut: %3d: ", count) ;
fflush (stdout) ;
serialPutchar (fd, count) ;
nextTime += 300 ;
++count ;
}
delay (3) ;
while (serialDataAvail (fd))
{
printf (" -> %3d", serialGetchar (fd)) ;
fflush (stdout) ;
}
}
printf ("\n") ;
return 0 ;
}

View File

@@ -1,57 +0,0 @@
/*
* servo.c:
* Test of the softServo code.
* Do not use this code - use the servoBlaster kernel module instead
*
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <wiringPi.h>
#include <softServo.h>
int main ()
{
if (wiringPiSetup () == -1)
{
fprintf (stdout, "oops: %s\n", strerror (errno)) ;
return 1 ;
}
softServoSetup (0, 1, 2, 3, 4, 5, 6, 7) ;
softServoWrite (0, 0) ;
/*
softServoWrite (1, 1000) ;
softServoWrite (2, 1100) ;
softServoWrite (3, 1200) ;
softServoWrite (4, 1300) ;
softServoWrite (5, 1400) ;
softServoWrite (6, 1500) ;
softServoWrite (7, 2200) ;
*/
for (;;)
delay (10) ;
}

View File

@@ -1,123 +0,0 @@
/*
* speed.c:
* Simple program to measure the speed of the various GPIO
* access mechanisms.
*
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#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) ;
if (wiringPiSetupGpio () == -1)
exit (1) ;
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:
if (wiringPiSetupSys () == -1)
exit (1) ;
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 ;
}

View File

@@ -1,111 +0,0 @@
/*
* test1.c:
* Simple test program to test the wiringPi functions
* This is a sequencer to make a patter appear on 8 LEDs
* connected to the GPIO pins.
*
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#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 ;
}

View File

@@ -1,58 +0,0 @@
/*
* test2.c:
* This tests the hardware PWM channel.
*
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#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 ;
}

View File

@@ -1,59 +0,0 @@
/*
* tone.c:
* Test of the softTone module in wiringPi
* Plays a scale out on pin 3 - connect pizeo disc to pin 3 & 0v
*
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <wiringPi.h>
#include <softTone.h>
#define PIN 3
int scale [8] = { 262, 294, 330, 349, 392, 440, 494, 525 } ;
int main ()
{
int i ;
if (wiringPiSetup () == -1)
{
fprintf (stdout, "oops: %s\n", strerror (errno)) ;
return 1 ;
}
softToneCreate (PIN) ;
for (;;)
{
for (i = 0 ; i < 8 ; ++i)
{
printf ("%3d\n", i) ;
softToneWrite (PIN, scale [i]) ;
delay (500) ;
}
}
}

View File

@@ -1,161 +0,0 @@
/*
* wfi.c:
* Wait for Interrupt test program
*
* This program demonstrates the use of the waitForInterrupt()
* function in wiringPi. It listens to a button input on
* BCM_GPIO pin 17 (wiringPi pin 0)
*
* The biggest issue with this method is that it really only works
* well in Sys mode.
*
* Jan 2013: This way of doing things is sort of deprecated now, see
* the wiringPiISR() function instead and the isr.c test program here.
*
* Copyright (c) 2012-2013 Gordon Henderson.
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <stdlib.h>
#include <wiringPi.h>
// A 'key' which we can lock and unlock - values are 0 through 3
// This is interpreted internally as a pthread_mutex by wiringPi
// which is hiding some of that to make life simple.
#define COUNT_KEY 0
// What BCM_GPIO input are we using?
#define BUTTON_PIN 17
// Debounce time in mS
#define DEBOUNCE_TIME 100
// globalCounter:
// Global variable to count interrupts
// Should be declared volatile to make sure the compiler doesn't cache it.
static volatile int globalCounter = 0 ;
/*
* waitForIt:
* This is a thread created using the wiringPi simplified threading
* mechanism. It will wait on an interrupt on the button and increment
* a counter.
*********************************************************************************
*/
PI_THREAD (waitForIt)
{
int state = 0 ;
int debounceTime = 0 ;
(void)piHiPri (10) ; // Set this thread to be high priority
for (;;)
{
if (waitForInterrupt (BUTTON_PIN, -1) > 0) // Got it
{
// Bouncing?
if (millis () < debounceTime)
{
debounceTime = millis () + DEBOUNCE_TIME ;
continue ;
}
// We have a valid one
state ^= 1 ;
piLock (COUNT_KEY) ;
++globalCounter ;
piUnlock (COUNT_KEY) ;
// Wait for key to be released
while (digitalRead (BUTTON_PIN) == LOW)
delay (1) ;
debounceTime = millis () + DEBOUNCE_TIME ;
}
}
}
/*
* setup:
* Demo a crude but effective way to initialise the hardware
*********************************************************************************
*/
void setup (void)
{
// Use the gpio program to initialise the hardware
// (This is the crude, but effective)
system ("gpio edge 17 falling") ;
// Setup wiringPi
wiringPiSetupSys () ;
// Fire off our interrupt handler
piThreadCreate (waitForIt) ;
}
/*
* main
*********************************************************************************
*/
int main (void)
{
int lastCounter = 0 ;
int myCounter = 0 ;
setup () ;
for (;;)
{
printf ("Waiting ... ") ; fflush (stdout) ;
while (myCounter == lastCounter)
{
piLock (COUNT_KEY) ;
myCounter = globalCounter ;
piUnlock (COUNT_KEY) ;
delay (500) ;
}
printf (" Done. myCounter: %5d\n", myCounter) ;
lastCounter = myCounter ;
}
return 0 ;
}