<오전>
Git 예제
Linux에 대한 설명
<오후>
gpio - v
gpio readall
WiringPi를 이용해 구현해보는 Raspberry Pi 예제
LED, 스위치
PINMAP
SW 1 | GP4
SW 2 | GP17
SW 3 | GP27
SW 4 | GP22
LED 1| GP23
LED 2| GP24
LED 3| GP25
LED 4| GP1
PIR | GP7
PIEZO| GP12
-- 라즈베리 파이 인터럽트 처리
https://blog.naver.com/simjk98/222175571376
#include <wiringPi.h>
#include <stdio.h>
#include <stdlib.h>
#define LED_PIN 4
int main(void) {
if (wiringPiSetup() == -1) {
printf("WiringPi 초기화 실패!\n");
return 1;
}
pinMode(LED_PIN, OUTPUT);
for (int i=0; i < 5; i++){
digitalWrite(LED_PIN, HIGH);
printf("LED 켜짐\n");
delay(1000);
digitalWrite(LED_PIN, LOW);
printf("LED 꺼짐\n");
delay(1000);
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <wiringPi.h>
//gpio 사용
#define LED_PIN 23
#define BUTTON_PIN 4
#define delay_val 300
int main(void){
if (wiringPiSetupGpio() == -1) {
printf("GPIO 초기화 실패!\n");
return 1;
}
pinMode(BUTTON_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
while(1){
if(digitalRead(BUTTON_PIN) == HIGH){
digitalWrite(LED_PIN, HIGH);
printf("Button Pushed..! -> LED ON\n");
delay(delay_val);
}
else {
digitalWrite(LED_PIN, LOW);
printf("LED OFF\n");
delay(delay_val);
}
}
return 0;
}
//ISR(Interrupt Service Routine) 구현
int led1_flag = 0;
void sw1_isr(void){
if(led1_flag == 0){
digitalWrite(LED_PIN,HIGH);
led1_flag=1;
} else {
digitalWrite(LED_PIN,LOW);
led1_flag=0;
}
prtintf("SW1 pushed..!!");
}
#include <stdio.h>
#include <pthread.h> // 목적파일 생성시 -lpthread 옵션 넣어주기
#include <unistd.h>
void* thread_main(void *arg){
int i;
int cnt = *((int*)arg);
for(i=0; i<cnt; i++){
sleep(1);
puts("running thread\n");
}
return NULL;
}
int main(int argc, char *argv[]){
//printf("%d\n",argc); // result : argc = 1 , argc = 인자들의 갯수 ex)./test a , argc = 2 ./test a,b ,argc = 3
//for(int i=0;i<argc;i++){
// printf("%s\n",argv[i]);} // result : ./test
pthread_t t_id;
int thread_param = 5;
if(pthread_create(&t_id, NULL, thread_main,(void*)&thread_param)!=0){
puts("pthread_create");
return -1;
}
sleep(10);
puts("end of main\n");
return 0;
}