daeun

modify lab2-3-2

No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
// Wiring Pi Library
#include <wiringPi.h>
const int LedRed[8] = { 4, 17, 18, 27, 22, 23, 24, 25 };
const int Keypad[5] = { 6, 12, 13, 16, 19 };
int KeypadRead()
{
int i, keypadnum = -1;
for (i = 0; i < 2; i++) {
if (!digitalRead(Keypad[i])) {
keypadnum = i; break;
}
}
return keypadnum;
}
void LedControl(int num)
{
int i;
for (i = 0; i < 8; i++) {
if (i == num)
digitalWrite(LedRed[i], HIGH);
else
digitalWrite(LedRed[i], LOW);
}
}
void stop() {
LedControl(-1);
}
int main(void)
{
int i, keypadnum = -1;
if (wiringPiSetupGpio() == -1)
return 1;
for (i = 0; i < 8; i++) {
pinMode(LedRed[i], OUTPUT);
digitalWrite(LedRed[i], LOW);
}
for (i = 0; i < 2; i++)
pinMode(Keypad[i], INPUT);
if (wiringPiISR(Keypad[2], INT_EDGE_FALLING, &stop) < 0) {
return 1;
}
while (1) {
keypadnum = KeypadRead();
if (keypadnum == 0) {
while (1) {
for (i = 0; i < 8; i++) {
LedControl(i);
delay(500);
}
digitalWrite(LedRed[i - 1], LOW);
}
}
else if (keypadnum == 1) {
while (1) {
for (i = 7; i >= 0; i--) {
LedControl(i);
delay(500);
}
digitalWrite(LedRed[i + 1], LOW);
}
}
if (keypadnum == 3) {
for (i = 0; i < 8; i++) {
LedControl(i);
delay(500);
}
digitalWrite(LedRed[i - 1], LOW);
}
else if (keypadnum == 4) {
for (i = 7; i >= 0; i--) {
LedControl(i);
delay(500);
}
digitalWrite(LedRed[i + 1], LOW);
}
}
return 0;
}
\ No newline at end of file
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
// Wiring Pi Library 헤더파일 선언
#include <wiringPi.h>
// LED ON/OFF 정의
#define LED_ON 1
#define LED_OFF 0
// 라즈베리파이 및 LED 핀 정의
const int Led[16] = {
4, 17, 18, 27, 22, 23, 24, 25,
6, 12, 13, 16, 19, 20, 26, 21
};
int main(void){
int i; // for문 변수
if(wiringPiSetupGpio() == -1) // GPIO 초기화
return 1;
for(i=0; i<16; i++){
pinMode(Led[i], OUTPUT); // LED 핀 출력모드 설정
digitalWrite(Led[i], LED_OFF); // LED 전체 OFF
}
while(1){
digitalWrite(Led[0], LED_ON); // LED 1 ON
delay(500); // 500ms 지연
digitalWrite(Led[0], LED_OFF); // LED 1 OFF
delay(500); // 500ms 지연
}
return 0;
}
\ No newline at end of file
#include <wiringPi.h>// Wiring Pi Library 헤더파일 선언
#define LED_OFF 0 // LED OFF 정의
#define LED_ON 1 // LED ON 정의
#define LED_RED 2 // LED RED 정의
#define LED_GREEN 3 // LED GREEN 정의
// 라즈베리파이 및 LED RED / GREEN 핀 정의
const int LedRed [8] = { 4, 17, 18, 27, 22, 23, 24, 25 };
const int LedGreen [8] = { 6, 12, 13, 16, 19, 20, 26, 21 };
void LEDControl(int color) {
int i;
if(color == LED_RED) {
for(i=0; i<8; i++) {
digitalWrite(LedRed[i], LED_ON);
digitalWrite(LedGreen[i], LED_OFF);
}
}
else if(color == LED_GREEN) {
for(i=0; i<8; i++) {
digitalWrite(LedRed[i], LED_OFF);
digitalWrite(LedGreen[i], LED_ON);
}
}
}
int main(void){
int i;
if(wiringPiSetupGpio() == -1)
return 1;
for(i=0; i<8; i++){
pinMode(LedRed[i], OUTPUT);
pinMode(LedGreen[i], OUTPUT);
digitalWrite(LedRed[i], LED_OFF);
digitalWrite(LedGreen[i], LED_OFF);
}
while(1){
LEDControl(LED_RED);
delay(500);
LEDControl(LED_GREEN);
delay(500);
}
return 0;
}
\ No newline at end of file
No preview for this file type
File mode changed
No preview for this file type
// Wiring Pi Library
#include <wiringPi.h>
const int LedRed[8] = { 4, 17, 18, 27, 22, 23, 24, 25 };
const int Keypad[2] = { 16, 19 };
int KeypadRead()
{
int i, keypadnum = -1;
for (i = 0; i < 2; i++) {
if (!digitalRead(Keypad[i])) {
keypadnum = i; break;
}
}
return keypadnum;
}
void LedControl(int num)
{
int i;
for (i = 0; i < 8; i++) {
if (i == num)
digitalWrite(LedRed[i], HIGH);
else
digitalWrite(LedRed[i], LOW);
}
}
int main(void)
{
int i, keypadnum = -1;
if (wiringPiSetupGpio() == -1)
return 1;
for (i = 0; i < 8; i++) {
pinMode(LedRed[i], OUTPUT);
digitalWrite(LedRed[i], LOW);
}
for (i = 0; i < 2; i++)
pinMode(Keypad[i], INPUT);
while (1) {
keypadnum = KeypadRead();
if (keypadnum == 0) {
for (i = 0; i < 8; i++) {
LedControl(i);
delay(500);
}
digitalWrite(LedRed[i - 1], LOW);
}
else if (keypadnum == 1) {
for (i = 7; i >= 0; i--) {
LedControl(i);
delay(500);
}
digitalWrite(LedRed[i + 1], LOW);
}
}
return 0;
}
\ No newline at end of file
No preview for this file type
No preview for this file type
No preview for this file type