Louie NRT Story

[RaspberryPi] Controll LED 본문

에너지

[RaspberryPi] Controll LED

hyeok0724.kim@gmail.com 2019. 5. 6. 21:20
반응형

[Design]

 

 

[RaspberryPi Code]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <stdio.h>
#include <wiringPi.h>
 
#define LED_PIN 27 // pin number
#define BT_PIN 0
 
int main(void){
        
        // wiringPi setup
        if(wiringPiSetup() == -1){
                return -1;
        }
 
        // pin = 27
        pinMode(LED_PIN, OUTPUT);
        pinMode(BT_PIN, INPUT);
        
        pullUpDnControl(BT_PIN, PUD_UP);
 
        // LED toggle
        while(1){
            if(!(digitalRead(BT_PIN)))
            {
                digitalWrite(LED_PIN,1); // pin 27, input 1, light ON
            delay(500); // Delay 0.5 sec
            digitalWrite(LED_PIN,0); // light OFF
            delay(500); // Delay 0.5 sec
            }
        }
        return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4f; text-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none; color:white">cs
반응형
Comments