2023年4月18日 星期二

反相放大電路

  • 應用目的:分析反相放大器之輸出波形。 
1. Rs=Rf
  • 電路圖



  • 波形



2. Rs=Rf/2
  • 電路圖

  • 波形

3. Rs=2*Rf
  • 電路

  • 波形


2023年4月9日 星期日

Using MQTT commands to control the action of animation in Three.js



1. three.js example: 
three.js examples (threejs.org)

2.HIVEMQ: https://www.mqtt-dashboard.com/

3.MQTT example:物動作控制

4.Publish

Topic:AnimationCommand

Commands: Idle, Walking, Running, Dance, Death, Sitting, Standing, Jump, Yes, No, Wave, Punch, ThumbsUp

5.Subscribe:

Topic: AnimtionState

2023年4月5日 星期三

Using MQTT commands to control lights in Three.js

In the upper right corner of the picture above, we can see two light control buttons are 'toggle directional light' and 'toggle hemisphere light', separately. You can try it out and learn how the two different lights work. For directional light, it is used to gets emitted in a specific direction but the light source of the hemisphere light position is located directly above the scene and the color of the light will gradually change from the color of the sky to the color of the ground.

1. three.js example: three.js examples (threejs.org)

2.MQTT example:Light Control

3.Publish

Topic:LightControlinHTML

Command 1:toggleHemisphereLight

Command 2:toggleDirectionalLight

4.Subscribe:

Topic: LightControl

We use MQTTBOX to test the issuance of commands as follows.


Host:test.mosquitto.org

Protocol:mqtt/tcp





2023年4月4日 星期二

使用Python讀取JSON格式的老年安養資料

資料網站:臺中市列冊獨居老人人數及服務概況
資料格式:臺中市列冊獨居老人人數及服務概況_JSON

1.首先下載資料,並改名為JSON.json。

2.撰寫下列基本程式:

1
2
3
4
5
import json
f = open('JSON.json')
data = json.load(f)
print(data)
f.close()

執行上面程式,發生如下的錯誤:
3. 這是編碼的問題,在開檔是只要告知是utf-8編碼格式即可,程式碼如下:

1
2
3
4
5
import json
f = open('JSON.json', encoding="utf-8")
data = json.load(f)
print(data)
f.close()

執行結果:

4.先用JSON工具來看資料的格式,https://jsoneditoronline.org/

5.依照格式修訂程式

1
2
3
4
5
6
7
8
9
import json
f = open('JSON.json', encoding="utf-8")
data = json.load(f)
data = data['ROOT']['RECORD']
for d in data:
    for r in d:
        print(r, ":", d[r])
    print("\n")
f.close()

執行結果:

6. 稍做整理,只留下行政區和合計人數,程式修訂如下:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
import json
f = open('JSON.json', encoding="utf-8")
data = json.load(f)
data = data['ROOT']['RECORD']
for d in data:
    for r in d:
        if r == "行政區" :
            print(d[r])
        if r == "合計":
            print(d[r])
    print("\n")
f.close()

執行結果:

7.用圖表來表示

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
import json
f = open('JSON.json', encoding="utf-8")
X=[]
Y=[]
data = json.load(f)
data = data['ROOT']['RECORD']
for d in data:
    for r in d:
        if r == "行政區" :
            X.append(d[r])
        if r == "合計":
            Y.append(d[r])
f.close()
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['mingliu']
plt.plot(X, Y)
plt.ylabel('(人)')
plt.show()

執行結果:

8. 我們發現圖形居然呈現線性的成長,再仔細看Y軸的數字,很怪,原來是字串並非數字,因此修改程式。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
import json
f = open('JSON.json', encoding="utf-8")
X=[]
Y=[]
data = json.load(f)
data = data['ROOT']['RECORD']
for d in data:
    for r in d:
        if r == "行政區" :
            X.append(d[r])
        if r == "合計":
            Y.append(int(d[r]))
f.close()
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['mingliu']
plt.plot(X, Y)
plt.ylabel('(人)')
plt.show()

執行結果: