Skip to content

Commit

Permalink
h3 chip gpio ok
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaolei committed Oct 23, 2015
1 parent 2a44e26 commit 3d1e4af
Show file tree
Hide file tree
Showing 8 changed files with 515 additions and 11 deletions.
83 changes: 83 additions & 0 deletions examples/echo.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* blink.c:
* Standard "blink" program in wiringPi. Blinks an LED connected
* to the first GPIO pin.
*
* 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 <wiringPi.h>
#include <sys/time.h>

#define TRIG 15
#define ECHO 16

float disT(void)
{
struct timeval tv1;
struct timeval tv2;

long start, stop;
float dis;

digitalWrite(TRIG, LOW);
delayMicroseconds(2);

digitalWrite(TRIG, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG, LOW);

while(!(digitalRead(ECHO) == 1)) {
gettimeofday(&tv1, NULL);
}

while(!(digitalRead(ECHO) == 0)) {
if(tv2.tv_sec - tv1.tv_sec > 10) break;
gettimeofday(&tv2, NULL);
}


start = tv1.tv_sec * 1000000 + tv1.tv_usec;
stop = tv2.tv_sec * 1000000 + tv2.tv_usec;

dis = (float) (stop - start) / 1000000 * 34000 / 2;

return dis;
}

int main (void)
{
float dis;

wiringPiSetup () ;

pinMode(TRIG, OUTPUT);
pinMode(ECHO, INPUT);

while(1)
{
dis = disT();
printf("dis: %f \n", dis);
delay(1200);
}

return 0 ;
}
59 changes: 59 additions & 0 deletions examples/te.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* blink.c:
* Standard "blink" program in wiringPi. Blinks an LED connected
* to the first GPIO pin.
*
* 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 <wiringPi.h>

// LED Pin - wiringPi pin 0 is BCM_GPIO 17.

#define LED 0

int leds[] = {16, 15,13, 9};

//16 15 13 9
int main (void)
{

int i;
printf ("Raspberry Pi blink\n") ;

wiringPiSetup () ;
pinMode (16, OUTPUT) ;
pinMode (15, OUTPUT) ;
pinMode (13, OUTPUT) ;
pinMode (9, OUTPUT) ;

for (;;)
{
for(i=0; i<4; i++) {
digitalWrite (leds[i], HIGH) ; // On
delay (20) ; // mS
digitalWrite (leds[i], LOW) ; // Off
delay (20) ;
}
delay(800);
}
return 0 ;
}
75 changes: 75 additions & 0 deletions examples/tser.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 ;
}
74 changes: 74 additions & 0 deletions examples/xserv.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* 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 (int argc, char *argv[])
{
if (wiringPiSetup () == -1)
{
fprintf (stdout, "oops: %s\n", strerror (errno)) ;
return 1 ;
}

int du = atoi(argv[2]) ;
int de = atoi(argv[1]) ;

du = (du == 0) ? 1000 : du;
de = (de == 0) ? 1000 : de;

softServoSetup (0, 1, 2, 3, 4, 5, 6, 16) ;

softServoWrite (0, 0) ;
/*
softServoWrite (1, 1000) ;
softServoWrite (2, 1100) ;
softServoWrite (3, 1200) ;
softServoWrite (4, 1300) ;
softServoWrite (5, 1400) ;
softServoWrite (6, 1500) ;
softServoWrite (7, 2200) ;
*/

//softServoWrite (16, du) ;
// delay (1500) ;
for (;;) {
softServoWrite (16, de) ;
delay (du) ;
softServoWrite (16, 0) ;
delay (du) ;
printf("%d \n", de);
softServoWrite (16, 0-de) ;
delay (du) ;
softServoWrite (16, 0) ;
delay (du) ;
}

}
Loading

0 comments on commit 3d1e4af

Please sign in to comment.