Skip to content
Snippets Groups Projects
Commit dc7b1d6a authored by LEESANGKYEONG's avatar LEESANGKYEONG
Browse files

HW update

parent f7f2457a
Branches
No related tags found
No related merge requests found
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <wiringPi.h>
#include <pthread.h>
#define RED 1
#define GREEN 4
#define YELLOW 5
void led_green_task(void *args);
void led_yellow_task(void *args);
\ No newline at end of file
#include "led.h"
void led_green_task(void* args) {
pinMode(GREEN, OUTPUT);
for (int i = 0; i < (int)args; i++) {
digitalWrite(GREEN, HIGH);
printf("GREEN TURN ON\n");
sleep(2);
digitalWrite(GREEN, LOW);
printf("GREEN TURN OFF\n");
sleep(2);
}
}
\ No newline at end of file
#include "led.h"
void led_red_task(void) {
pinMode(RED, OUTPUT);
for (int i = 0; i < 10; i++) {
digitalWrite(RED, HIGH);
printf("RED TURN ON\n");
sleep(1);
digitalWrite(RED, LOW);
printf("RED TURN OFF\n");
sleep(1);
}
}
int main(int argc, char* argv[]) {
int gno;
int time;
wiringPiSetup();
if (argc < 2) {
printf("Insert Correct value, try again\n");
exit(-1);
}
gno = atoi(argv[1]);
time = atoi(argv[2]);
pthread_t G;
pthread_t Y;
if (gno == 1) {
if ((pthread_create(&G, NULL, led_green_task, (void*)time)) < 0) {
perror("thread create error:");
exit(0);
}
}
else if (gno == 2) {
if ((pthread_create(&Y, NULL, led_yellow_task, (void*)time)) < 0){
perror("thread create error:");
exit(0);
}
}
else if (gno == 3) {
if ((pthread_create(&G, NULL, led_green_task, (void*)time)) < 0) {
perror("thread create error:");
exit(0);
}
if ((pthread_create(&Y, NULL, led_yellow_task, (void*)time)) < 0){
perror("thread create error:");
exit(0);
}
}
led_red_task();
pthread_exit(NULL);
return 0;
}
\ No newline at end of file
#include "led.h"
void led_yellow_task(void* args) {
pinMode(YELLOW, OUTPUT);
for (int i = 0; i < (int)args; i++) {
digitalWrite(YELLOW, HIGH);
printf("YELLOW TURN ON\n");
sleep(3);
digitalWrite(YELLOW, LOW);
printf("YELLOW TURN OFF\n");
sleep(3);
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment