?

단축키

Prev이전 문서

Next다음 문서

+ - Up Down Comment Print
?

단축키

Prev이전 문서

Next다음 문서

+ - Up Down Comment Print

참고: http://blog.prettymay.com/220670957502


[설치]

$ sudo apt-get install lirc liblircclient-dev


[핀설정]

$ sudo nano /etc/modules

파일 끝에 아래 내용을 추가

lirc_dev

lirc_rpi gpio_in_pin=18  <-- 연결된 핀번호


$ sudo nano /etc/lirc/hardware.conf

아래내용으로 수정

LIRCD_ARGS="--uinput"

DRIVER="default"

DEVICE="/dev/lirc0"

MODULES="lirc_rpi"


$ sudo nano /boot/config.txt


[수신확인]

$ sudo /etc/init.d/lirc stop

$ mode2 -d /dev/lirc0


[키와 매핑하기 (record)]

$ irrecord -d /dev/lirc0 ~/lircd.conf

그러면 모든 키를 입력라하는 말이 나옴. 그과정에 lircd.conf 파일이 만들어짐


$sudo cp ~/lircd.conf /etc/lirc/lircd.conf

덮어 쓰기.


[데몬 시작]

$ sudo /etc/init.d/lirc restart



테스트 소스


#include <wiringPi.h>
#include <lirc/lirc_client.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#define LED_B	4
#define LED_R	5
#define LED_G	6

#define LED_ON	1
#define LED_OFF	0

void ledOnOff(int led) {
	if (digitalRead(led) == LED_ON)
		digitalWrite(led, LED_OFF);
	else
		digitalWrite(led, LED_ON);
}

int main() {
	struct lirc_config *config;

	int buttonTimer = millis();
	char *code;

	if (wiringPiSetup() == -1) 
		exit(1);

	pinMode(LED_B, OUTPUT);
	pinMode(LED_R, OUTPUT);
	pinMode(LED_G, OUTPUT);

	if (lirc_init("lirc", 1) == -1)
		exit(EXIT_FAILURE);

	if (lirc_readconfig(NULL, &config, NULL) == 0) {
		while (lirc_nextcode(&code) == 0) {
			if (code == NULL)
				continue;

			if (millis() - buttonTimer > 400) {
				if (strstr(code, "KEY_1")) {
					printf("Match on KEY_1\n");
					ledOnOff(LED_B);
					buttonTimer = millis();
				} else if (strstr(code, "KEY_2")) {
					printf("Match on KEY_2\n");
					ledOnOff(LED_R);
					buttonTimer = millis();
				} else if (strstr(code, "KEY_3")) {
					printf("Match on KEY_3\n");
					ledOnOff(LED_G);
					buttonTimer = millis();
				}
			}

			free(code);
		}

		lirc_freeconfig(config);
	}

	lirc_deinit();
	exit(EXIT_SUCCESS);
}






Dreamy의 코드 스크랩

내가 모으고 내가 보는

List of Articles
번호 분류 제목 날짜 조회 수 추천 수
476 LINUX Ubuntu php5.6 , php7.1 설치 및 셋팅하기 2020.02.11 5180 0
475 LINUX Ubuntu apt-get 명령어 정리 2020.02.11 4003 0
474 LINUX 우분투(Ubuntu) 설치된 패키지 목록 확인하기 2020.02.11 20595 0
473 일반 온습도, 미세먼지 정보 받아오기 secret 2020.01.10 0 0
472 Pi 아두이노 데이터 저장하기(Arduino EEPROM 사용하기) 2019.12.24 17835 0
471 LINUX mutt Gmail 설치, 사용 / Ubuntu 18.04 환경 2019.11.25 5045 0
470 LINUX 리눅스 명령행에서 메일 보내기(send mail from linux command line) 2019.11.25 9052 0
469 LINUX Ubuntu TFTP 서버 2019.10.30 7085 0
468 Pi 레귤레이터(3.3V 1A) KA78R33 데이터시트 file 2019.08.20 3785 0
467 Pi 회로부품 메모 1 secret 2019.08.09 1 0
466 Pi OP AMP의 활용 2019.08.05 9848 0
465 Python Image 기반 Steganography 예제 1 2019.07.17 25466 0
464 업무 Pen Testing 툴 요약 secret 2019.07.16 0 0
463 일반 SQL Injection 우회 정리 2019.07.10 8027 0
462 C C에서 파일 존재여부 체크 (check file exist) 2019.07.02 18482 0
목록
Board Pagination ‹ Prev 1 2 3 4 5 6 7 8 9 10 ... 34 Next ›
/ 34

나눔글꼴 설치 안내


이 PC에는 나눔글꼴이 설치되어 있지 않습니다.

이 사이트를 나눔글꼴로 보기 위해서는
나눔글꼴을 설치해야 합니다.

설치 취소

Designed by sketchbooks.co.kr / sketchbook5 board skin

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5