Recent Posts
printf("ho_tari\n");
Thread5 (SWITCH_LED_ON_OFF) 본문
<main.c>
#include <stdio.h>
#include <wiringPi.h>
#include <pthread.h>
#define LED1 23
#define LED2 24
#define SW1 4
#define SW2 17
int led1_flag = 0;
int led2_flag = 0;
int sw1_flag = 0;
int sw2_flag = 0;
pthread_t thread1, thread2;
void *led1(void *arg)
{
while (1)
{
if (led1_flag == 1)
{
digitalWrite(LED1, HIGH);
delay(300);
digitalWrite(LED1, LOW);
delay(300);
}
}
}
void *led2(void *arg)
{
while (1)
{
if (led2_flag == 1)
{
digitalWrite(LED2, HIGH);
delay(500);
digitalWrite(LED2, LOW);
delay(500);
}
}
}
void sw1(void)
{
if (led1_flag == 0)
{
led1_flag = 1;
}
else
{
led1_flag = 0;
digitalWrite(LED1, LOW);
}
}
void sw2(void)
{
if (led2_flag == 0)
{
led2_flag = 1;
}
else
{
led2_flag = 0;
digitalWrite(LED2, LOW);
}
}
int main()
{
if (wiringPiSetupGpio() == -1) return -1;
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(SW1, INPUT);
pinMode(SW2, INPUT);
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
wiringPiISR(SW1, INT_EDGE_RISING, &sw1);
wiringPiISR(SW2, INT_EDGE_RISING, &sw2);
pthread_create(&thread1, NULL, led1, NULL);
pthread_create(&thread2, NULL, led2, NULL);
while (1)
{
}
return 0;
}
'Raspberry Pi' 카테고리의 다른 글
Thread4 (0) | 2023.10.06 |
---|---|
Thread3 (0) | 2023.10.06 |
Thread2 (0) | 2023.10.06 |
Thread1 (0) | 2023.10.05 |
SWITCH_LED_INTERRUPT (0) | 2023.10.05 |