前面的方法可以参照(一)来配置GPIO口。
下面是代码。。。仅供参考,转载请注明出处。
1. 先输入以下指令,再复制代码,Ctrl+X 输入Y 回车 保存。
sudo nano start.c
#include "car.h" #include <stdio.h> #include <stdlib.h> #include <wiringPi.h> #include <sys/time.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <netdb.h> #include <string.h> #include <errno.h> #include <unistd.h> #define IN1 0 // wiringPi GPIO0(pin11) car.GPIO #define IN2 1 #define IN3 2 #define IN4 3 #define IN5 4 //Ultrasound module.GPIO send #define IN6 5 // accept /* Write By ITJoker Time:2.18.2.4 Version:1.0 */ int up() { wiringPiSetup() ; pinMode (IN1, OUTPUT) ; pinMode (IN2, OUTPUT) ; pinMode (IN3, OUTPUT) ; pinMode (IN4, OUTPUT) ; digitalWrite(IN1, HIGH) ; delay (500) ; digitalWrite(IN2, LOW) ; delay (500) ; digitalWrite(IN3, HIGH) ; delay (500) ; digitalWrite(IN4, LOW) ; delay (500) ; } int down() { wiringPiSetup() ; pinMode (IN1, OUTPUT) ; pinMode (IN2, OUTPUT) ; pinMode (IN3, OUTPUT) ; pinMode (IN4, OUTPUT) ; digitalWrite(IN1, LOW) ; delay (500) ; digitalWrite(IN2, HIGH) ; delay (500) ; digitalWrite(IN3, LOW) ; delay (500) ; digitalWrite(IN4, HIGH) ; delay (500) ; } int right() { wiringPiSetup() ; pinMode (IN1, OUTPUT) ; pinMode (IN2, OUTPUT) ; pinMode (IN3, OUTPUT) ; pinMode (IN4, OUTPUT) ; digitalWrite(IN1, LOW) ; delay (500) ; digitalWrite(IN2, HIGH) ; delay (500) ; digitalWrite(IN3, HIGH) ; delay (500) ; digitalWrite(IN4, LOW) ; delay (500) ; } int left() { wiringPiSetup() ; pinMode (IN1, OUTPUT) ; pinMode (IN2, OUTPUT) ; pinMode (IN3, OUTPUT) ; pinMode (IN4, OUTPUT) ; digitalWrite(IN1, HIGH) ; delay (500) ; digitalWrite(IN2, LOW) ; delay (500) ; digitalWrite(IN3, LOW) ; delay (500) ; digitalWrite(IN4, HIGH) ; delay (500) ; } int stop() { wiringPiSetup() ; pinMode (IN1, OUTPUT) ; pinMode (IN2, OUTPUT) ; pinMode (IN3, OUTPUT) ; pinMode (IN4, OUTPUT) ; digitalWrite(IN1, LOW) ; delay (500) ; digitalWrite(IN2, LOW) ; delay (500) ; digitalWrite(IN3, LOW) ; delay (500) ; digitalWrite(IN4, LOW) ; delay (500) ; } int main(int argc, char *argv[]) { int fd, new_fd, struct_len, numbytes,i; struct sockaddr_in server_addr; struct sockaddr_in client_addr; char buff[BUFSIZ]; server_addr.sin_family = AF_INET; server_addr.sin_port = htons(8888);//port 8888 server_addr.sin_addr.s_addr = INADDR_ANY; bzero(&(server_addr.sin_zero), 8); struct_len = sizeof(struct sockaddr_in); fd = socket(AF_INET, SOCK_STREAM, 0); while(bind(fd, (struct sockaddr *)&server_addr, struct_len) == -1); printf("Bind Success! "); while(listen(fd, 10) == -1); printf("Listening.... "); printf("Ready for Accept,Waitting... "); new_fd = accept(fd, (struct sockaddr *)&client_addr, &struct_len); printf("Get the Client. "); // numbytes = send(new_fd,"Welcome to my server ",21,0); while((numbytes = recv(new_fd, buff, BUFSIZ, 0)) > 0) { buff[numbytes] = '