guowenxue
2019-01-30 b06022623775de9ab47ef1ce355c5ecd134b8529
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*********************************************************************************
 *      Copyright:  (C) 2019 LingYun IoT System Studio
 *                  All rights reserved.
 *
 *       Filename:  infrared.c
 *    Description:  This file 
 *                 
 *        Version:  1.0.0(30/01/19)
 *         Author:  Guo Wenxue <guowenxue@gmail.com>
 *      ChangeLog:  1, Release initial version on "30/01/19 03:37:16"
 *                 
 ********************************************************************************/
 
#include <stdio.h>
#include <unistd.h>
#include <wiringPi.h>
 
/* I/O Pin connected to PIN#16, BCM code pin number is 23 and wPi pin number is 4 */
#define INFRARED_PIN           4
 
int main (int argc, char **argv)
{
    wiringPiSetup();
    pinMode(INFRARED_PIN, INPUT);
 
    while(1)
    {
        printf("Infrared monitor: %s\n", digitalRead(INFRARED_PIN)? "Someone is closing!":"No one nearby!");
        sleep(1);
    }
 
 
    return 0;
}