Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
xpertsavenue authored Jan 24, 2017
1 parent 0c4ed45 commit 38174b3
Show file tree
Hide file tree
Showing 10 changed files with 787 additions and 0 deletions.
48 changes: 48 additions & 0 deletions examples/serialRead.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* serial.c:
* Example program to read bytes from the Serial line
*
* Copyright (c) 2012-2013 Gordon Henderson. <[email protected]>
***********************************************************************
* 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/ttyS2", 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) ;
}
}
75 changes: 75 additions & 0 deletions examples/serialTest.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* 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. <[email protected]>
***********************************************************************
* 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 ;
}
57 changes: 57 additions & 0 deletions examples/servo.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* servo.c:
* Test of the softServo code.
* Do not use this code - use the servoBlaster kernel module instead
*
* Copyright (c) 2012-2013 Gordon Henderson. <[email protected]>
***********************************************************************
* 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) ;

}
89 changes: 89 additions & 0 deletions examples/softPwm.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* softPwm.c:
* Test of the software PWM driver. Needs 8 LEDs connected
* to the Pi - e.g. Ladder board.
*
* Copyright (c) 2012-2013 Gordon Henderson. <[email protected]>
***********************************************************************
* 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 8

int ledMap [NUM_LEDS] = { 0, 1, 2, 3, 4, 5, 6, 7 } ;

int values [NUM_LEDS] = { 0, 25, 50, 75, 100, 75, 50, 25 } ;

int main ()
{
int i, j ;
char buf [80] ;

wiringPiSetup () ;

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) ;

// All Down

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 ;
}
}
54 changes: 54 additions & 0 deletions examples/softTone.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* softTone.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. <[email protected]>
***********************************************************************
* 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 ;

wiringPiSetup () ;

softToneCreate (PIN) ;

for (;;)
{
for (i = 0 ; i < 8 ; ++i)
{
printf ("%3d\n", i) ;
softToneWrite (PIN, scale [i]) ;
delay (500) ;
}
}
}
Loading

0 comments on commit 38174b3

Please sign in to comment.