?

단축키

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
번호 분류 제목 날짜 조회 수 추천 수
461 LINUX gdb 쓸때 상용구 secret 2019.06.26 0 0
460 Pi 라즈베리파이 내 작업 명령 secret 2019.06.10 0 0
459 일반 범용 레지 스터(eax, ebx, ecx, edx, esi, edi, esp, ebp) 2019.06.03 9690 0
458 Python 디렉토리 없으면 만들기 2019.03.30 5710 0
457 Python 줄 바꿈 없이 출력하는 방법 2019.03.30 6798 0
456 LINUX Ubuntu에서 Python 버전을 변경하는 방법 2019.03.29 11956 0
455 Python Google Colab에서 파일 업로드/다운로드 팁 2019.03.06 36402 0
454 Python pandas, matplot 자주사용하는 코드 2019.03.06 4879 0
453 Python matplot에서 한글이 보이도록 하는 코드 2019.03.06 6015 0
452 일반 OMV (OpenMediaVault) 플러그인들 2019.02.10 7923 0
451 일반 ddns 정보 secret 2019.02.10 0 0
450 Android git archive 를 사용해서 폴더를 .git 제외하고 tar 나 zip 으로 묶기 1 2019.02.10 7025 0
449 LINUX vi 설정하기(.vimrc) 2019.02.01 5340 0
448 Pi 칩 저항 사이즈표, 사이즈변환, 와트, 오차표 2019.01.11 10419 0
447 Pi NPN과 PNP 트랜지스터의 차이 2019.01.03 13845 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