- 라즈베리파이 보드 빵판 21번 핀에 led를 연결해놓고, 웹서버에서 ON/OFF 버튼으로 LED를 껐다 켰다 하는 프로그램
<app.py>
import RPi.GPIO as GPIO
from flask import Flask, render_template
app=Flask(__name__)
GPIO.setmode(GPIO.BCM)
GPIO.setup(21,GPIO.OUT)
def led_on():
GPIO.output(21,0)
return
def led_off():
GPIO.output(21,1)
return
@app.route('/')
def index():
led_off()
return render_template('index.html',state='OFF')
@app.route('/on/')
def on():
led_on()
print('switch on')
return render_template('index.html',state='ON')
@app.route('/off/')
def off():
led_off()
print('switch off')
return render_template('index.html',state='OFF')
if __name__ == '__main__':
print('web Server Starts')
app.run(debug=True, host='0.0.0.0')
print('web server ends')
GPIO.cleanup()
print("program ends")
<index.html>
<!doctype html>
<html>
<head>
<title> GPIO INPUT/OUTPUT DEMO </title>
<link type="text/css" rel="stylesheet" href="/static/style.css"/>
</head>
<body>
<div calss="onoff"><a href="/on">ON</a></div>
<div calss="onoff"><a href="/off">OFF</a></div>
<br/>
<p> LED is now <span id="state">{{state}}</span> state.</p>
</body>
</html>
<style.css>
body {
background-color:black;
text-align:center;
}
div.onoff a{
color:white;
font-size=200px;
text-decoration=none;
}
p{
font-size:50px;
color:yellow;
}
#state{
font-size:80px;
color:red;
}
'FW 심화 과정 > [2] STM32심화실습' 카테고리의 다른 글
0720 형식지정자(typedef) / 매크로 ~84 (0) | 2022.07.21 |
---|---|
0719 스택 / keil메모리값변화 / 포인터 ~64 (0) | 2022.07.19 |
0718 16진수용량계산 / ROM,RAM / Keil (0) | 2022.07.18 |
0715 인터럽트 / I2C를 이용한 가속도센서 (0) | 2022.07.17 |
[4주차 세미나] 포트포워딩 분석 (0) | 2022.07.16 |
0714 라즈베리파이 bread board 제어, 스레드 구현 (0) | 2022.07.14 |