「防疫大作戰」之機電整合分享:
新北市三重區明志國中 2020 科技專案 [1]
Email:Lct4246@gmail.com
FB:http://gg.gg/TedLeeFB/
專案說明
專案架構
1. 機構設計
2. 機電整合電路設計
- 計時:按下啟動按鈕後開始倒數 2 分鐘(120秒)並於燈板上顯示剩餘時間。
- 計分:有球進洞後需計分並於燈板上顯示累計得分。
- 重置(reset):按下啟動按鈕後轉動病毒轉盤重新開局。
品名 |
單位 |
數量 |
用途 |
|
1 |
Nano(FT232晶片) |
片 |
2 |
計分及計時燈板控制 |
2 |
mini USB傳輸線 |
條 |
2 |
計分及計時燈板控制 |
3 |
Lumex
LDM-6432-P5-BLE4-1燈板 |
組 |
2 |
計分及計時燈板控制 |
4 |
麵包板 |
塊 |
2 |
計分及計時燈板控制 |
5 |
延長線 |
組 |
1 |
電源供應控制 |
6 |
(藍)FB-002-34雙孔USB充電器 |
個 |
2 |
電源供應 |
7 |
杜邦(10cm) |
組 |
1 |
系統接線 |
8 |
杜邦(20cm) |
組 |
1 |
系統接線 |
9 |
單心線 |
組 |
1 |
系統接線 |
10 |
繼電器 |
個 |
1 |
AC馬達控制 |
11 |
按鈕開關 |
組 |
1 |
系統啟動按鈕 |
12 |
微動開関 |
個 |
1 |
計分感應 |
13 |
10KΩ電阻 |
個 |
2 |
啟動按鈕、計分感應電路 |
3. 機電整合控制程式設計
#define relay_pin 3 #define sss_pin 12
const int buttonPin = 2; // the number of the pushbutton pin
// Variables will change: //int ledState = HIGH; // the current state of the output
pin int buttonState; // the current reading from the
input pin int lastButtonState = LOW; // the previous reading from the input pin
// the following variables are
unsigned longs because the time, measured in // milliseconds, will quickly become a
bigger number than can be stored in an int. unsigned long lastDebounceTime =
0; // the last time the output pin was
toggled unsigned long debounceDelay = 50; // the debounce time; increase if the
output flickers
void ini() {
lastButtonState = LOW;
lastDebounceTime = 0; }
void setup() {
pinMode(relay_pin, OUTPUT);
pinMode(buttonPin, INPUT);
pinMode(sss_pin, OUTPUT);
Serial.begin(115200);
//設定UART
delay(1000);
Serial.print("atd0=()"); //清除畫面
while (Serial.read() != 'E') {}
//等待燈板完成動作
Serial.print("at2b=(0)"); //設定為覆蓋模式
while (Serial.read() != 'E') {}
//傳送指令終止的字元 } //end of setup()
void loop() {
// read the state of the switch into a local variable:
int reading = digitalRead(buttonPin);
// check to see if you just pressed the button
// (i.e. the input went from LOW to HIGH), and you've waited long
enough
// since the last press to ignore any noise:
// If the switch changed, due to noise or pressing:
if (reading != lastButtonState) {
// reset the debouncing timer
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
// whatever the reading is at, it's been there for longer than the
debounce delay, so take it as the actual current state:
// if the button state has changed:
if (reading != buttonState) {
buttonState = reading;
// only toggle the LED if the new button state is HIGH
if (buttonState == HIGH) {
//Spin the wheel
digitalWrite(relay_pin, HIGH);
//Score counting
digitalWrite(sss_pin, HIGH);
//Time counting
//Serial.print("atef=(4)"); //設定文字顏色為綠色
//while (Serial.read() != 'E') {}
//Serial.print("at83=(1,0,Count:)"); //顯示8x16字型 Count: 字串
//while (Serial.read() != 'E') {}
Serial.print("atef=(32)"); //設定數字顏色為0:Black、3:B、4:G、32:R
while (Serial.read() != 'E') {}
for (int i = 120; i > 0; i--) { Serial.print("atd0=()");
//清除畫面 while (Serial.read() != 'E') {} //等待燈板完成動作
Serial.print("at83=(1,3,"); //傳送部分指令 Serial.print((String)i); //傳送指令中變動的部分 Serial.write(')'); //傳送指令終止的字元 while (Serial.read() != 'E') {}
delay(950);
//Serial.print("atd0=()"); //清除畫面 //while (Serial.read() != 'E')
{} //等待燈板完成動作
} //end of for loop
digitalWrite(sss_pin, LOW);
digitalWrite(relay_pin, LOW);
} //end of if
} //end of if
} //end of if
// save the reading. Next time through the loop, it'll be the
lastButtonState:
lastButtonState = reading;
//ini(); } //end of loop() |
#define sss_pin 12 #define micro_sw_pin A0
int i = 0; int x = 0;
float debounce_time = 1; int start_time = 0; int end_time = 0;
void setup() {
pinMode(micro_sw_pin, INPUT);
pinMode(sss_pin, INPUT);
Serial.begin(115200);
//設定UART
delay(1000);
Serial.print("atd0=()"); //清除畫面
while (Serial.read() != 'E') {}
//等待燈板完成動作
Serial.print("at2b=(0)");
//設定為覆蓋模式
while (Serial.read() != 'E') {}
//傳送指令終止的字元 } //end of setup()
void loop() {
while (digitalRead(sss_pin)) {
Serial.print("atef=(4)"); //設定數字顏色為0:Black、3:B、4:G、32:R
while (Serial.read() != 'E') {}
//Serial.print("atd0=()");
//while (Serial.read() != 'E') {}
x = analogRead(micro_sw_pin);
if (x < 10) {
//scoring();
//i=10;
++i;
Serial.print("atd0=()"); //清除畫面
while (Serial.read() != 'E') {} //等待燈板完成動作
Serial.print("at83=(1,3,"); //傳送部分指令
Serial.print(i);
//傳送指令中變動的部分
Serial.write(')');
//傳送指令終止的字元
while (Serial.read() != 'E') {}
delay(500);
} //end of if
} //end of while
i=0; } //end of loop()
void scoring() {
//i=11;
//int x = 0;
//x = analogRead(micro_sw_pin);
//Serial.println(x);
start_time = millis();
while (x <10) {
//i=12;
//Serial.print("start_time=");
//Serial.println(start_time);
if (x > 1000) {
//i=13;
end_time = millis();
//Serial.print("end_time=");
//Serial.println(end_time);
//break;
} //end of if
x = analogRead(micro_sw_pin);
} //end of while
//i = end_time - start_time;
if ((end_time - start_time) > debounce_time ) {
//i=14;
//Serial.print("i=");
//Serial.println(++i);
++i;
start_time = 0;
end_time = 0;
} } |
未來擴充
- 本專案因已過保密年限,並經由明志國中(戴春成校長與林耀坤主任)同意而公開分享「機電整合」之技術內容,以供各方同好參考。
- 六種授權條款。
沒有留言:
張貼留言