목록Raspberry PI(C) (6)
Creative Code
#include #include #include #include #define LED_1 23 #define LED_2 24 #define SW_1 4 #define SW_2 17 int LED1_flag = 0; int LED2_flag = 0; void sw1_interrupt() { if (LED1_flag == 0) { LED1_flag = 1; } else { LED1_flag = 0; } } void sw2_interrupt() { if (LED2_flag == 0) { LED2_flag = 1; } else { LED2_flag = 0; } } void* thread1_main(void *arg) { while (1) { if (LED1_flag == 0) { digitalWrite(LED_..
#include #include #include #include #include void* thread_main(void *arg); int main(int argc, char *argv[]) { pthread_t t_id; int thread_param=5; void * thr_ret; if(pthread_create(&t_id, NULL, thread_main, (void*)&thread_param)!=0) { puts("pthread_create() error"); return -1; }; if(pthread_join(t_id, &thr_ret)!=0) { puts("pthread_join() error"); return -1; }; printf("Thread return message: %s \n..
#include #include #include void* thread1_main(void *arg) { int i; int cnt = *((int*)arg); for (i = 0; i < cnt; i++) { sleep(1); puts("running thread..1\n"); } return 10; } void* thread2_main(void *arg) { int i; int cnt = *((int*)arg); for (i = 0; i < cnt; i++) { sleep(1); puts("running thread..2\n"); } return NULL; } int main(int argc, char *argv[]) { pthread_t t1_id, t2_id; int thread_param = 5..
#include #include #include // 스레드에서 실행되는 함수 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[]) { pthread_t t_id; int thread_param = 5; // 스레드 생성 if (pthread_create(&t_id, NULL, thread_main, (void*)&thread_param) != 0) { puts("pthread_create() error\n"..
#include #include // LED 핀 및 스위치 핀 정의 #define LED_1 23 #define SW_1 4 // LED와 스위치 상태를 나타내는 변수 int LED1_flag = 0; int SW1_flag = 0; // 스위치 인터럽트 핸들러 함수 void sw_interrupt() { // LED1 상태 토글 if (LED1_flag == 0) { digitalWrite(LED_1, HIGH); // LED1 켜기 LED1_flag = 1; } else { digitalWrite(LED_1, LOW); // LED1 끄기 LED1_flag = 0; } SW1_flag = 1; // 스위치 상태 업데이트 } int main(void) { // WiringPi 라이브러리 초기화 if (..
#include int main(void) { // WiringPi 라이브러리를 초기화합니다. if (wiringPiSetupGpio() == -1) return -1; // GPIO 핀을 출력 모드로 설정합니다. pinMode(23, OUTPUT); pinMode(24, OUTPUT); pinMode(25, OUTPUT); pinMode(1, OUTPUT); // 5번 반복하는 루프 for (int i = 0; i < 5; i++) { // 23번 핀을 HIGH로 설정하여 LED를 켭니다. digitalWrite(23, HIGH); delay(1000); // 1초 동안 대기합니다. // 23번 핀을 LOW로 설정하여 LED를 끕니다. digitalWrite(23, LOW); delay(1000); /..