• 검색 결과가 없습니다.

버튼 한번 누름 0 0 0 1 5

N/A
N/A
Protected

Academic year: 2022

Share "버튼 한번 누름 0 0 0 1 5"

Copied!
1
0
0

로드 중.... (전체 텍스트 보기)

전체 글

(1)

1 // LED 를 제어하는 프로그램을 작성하시오. int 형 변수 count 의 값을 2진수 형태로 LED 에 표시할 것 . 버튼을 누를 때마다 의 값을 씩 증가시킬 것

count 1 . 2

3 // LED 초기상태 0 0 0 0 4 // 버튼 한번 누름 0 0 0 1 5 // 다시 한번 누름 0 0 1 0 6 // 다시 한번 누름 0 0 1 1 7 // 푸쉬 버튼 누름 0 1 0 0 8 // 같은 형태로 반복

9

10 #include <wiringPi.h>

11

12 int main() 13 {

14 const int button_pin=21;

15 const int led_pin[]={25,29,28,27};

16 const int led_count=sizeof(led_pin)/sizeof(led_pin[0]);

17

18 wiringPiSetup();

19

20 pinMode(button_pin, INPUT);

21 for(int i=0;i<led_count;++i){

22 pinMode(led_pin[i], OUTPUT);

23 digitalWrite(led_pin[i], LOW);

24 } 25

26 int input_prev=HIGH, input_cur=HIGH;

27 int count=0;

28

29 while(1){

30 input_cur=digitalRead(button_pin);

31

32 if(input_prev==HIGH && input_cur==LOW)

33 ++count;

34

35 input_prev=input_cur;

36

37 for(int i=0;i<led_count;++i)

38 digitalWrite(led_pin[i], (count&(1<<i)?HIGH:LOW));

39

40 delay(20);

41 } 42

43 return 0;

44 } 45

참조

관련 문서

Current chronic obstructive pulmonary disease (COPD) guidelines recommend using inhaled corticosteroids (ICS) in patients whose airflow limitation is severe

[r]

[r]

[r]

일본 자동차 제조사, 인니 Patimban항 운영권 획득

[r]

신선화물 거래 증가로 대형 컨테이너선사 중심 냉장 컨테이너 주문 폭주2. UN 조달시장 기업진출

[r]