SlideShare a Scribd company logo
1 of 23
卓爾榮譽學會創客工作坊 2018
卓爾創客工作坊
2018 / 05 / 19
卓爾榮譽學會創客工作坊 2018
課程目標
複習Arduino中
C++語言的使用,
並且學習一些新的
語法
了解感測器模組、
馬達控制板運作方
式
將兩者結合使自走車
動起來
卓爾榮譽學會創客工作坊 2018
Review
› digitalWrite(pin, value);
› analogWrite(pin, value);
› digitalRead(pin);
› analogRead(pin);
› if… else…
› for( ; ; )
pinMode(pin, type)
卓爾榮譽學會創客工作坊 2018
練習題
› 使用兩個LED和一個可變電阻,其中一個
LED在可變電阻轉超過一半前不亮,超過一
半後才點亮,另一個則跟著可變電阻由暗
轉亮。
› Hint: if, analogRead, digitalWrite,
analogWrite
卓爾榮譽學會創客工作坊 2018
控制程式 Linkit 7688 自走車
( 感測器與馬達 )
Android
App
卓爾榮譽學會創客工作坊 2018
直流馬達 (DC motor)
A B 動作
0 0
5 0
0 5
3 0
0 3
5 5
不動
正轉
反轉
正轉
反轉
不動
卓爾榮譽學會創客工作坊 2018
4個輸出控制兩個輪子的正反轉
卓爾榮譽學會創客工作坊 2018
A B C D
5 0 5 0 前進
0 5 0 5
5 0 0 0
0 0 5 0
3 0 5 0
後退
右旋
左旋
左彎
反 反
正 停
停 正
正 正
卓爾榮譽學會創客工作坊 2018
卓爾榮譽學會創客工作坊 2018
A B C D
5 0 5 0 前進
0 5 0 5
5 0 0 0
0 0 5 0
3 0 5 0
後退
右彎
左彎
左彎
反 反
正 停
停 正
正 正
卓爾榮譽學會創客工作坊 2018
A B C D
5 0 5 0 前進
0 5 0 5
5 0 0 0
0 0 5 0
3 0 5 0
後退
右彎
左彎
左彎
反 反
正 停
停 正
正 正
void setup() {
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(6, OUTPUT);
pinMode(5, OUTPUT);
}
void loop() {
analogWrite(10, 255);
analogWrite(9, 0);
analogWrite(6, 255);
analogWrite(5, 0);
}
卓爾榮譽學會創客工作坊 2018
練習
int L1=10, L2=9, R1=6, R2=5;
void setup() {
pinMode(L1, OUTPUT);
pinMode(L2, OUTPUT);
pinMode(R1, OUTPUT);
pinMode(R2, OUTPUT);
}
void loop() {
analogWrite(L1, 255);
analogWrite(L2, 0);
analogWrite(R1, 255);
analogWrite(R2, 0);
}
挑戰:
兩顆輪子
靜止→正轉越轉越快→最快→
越轉越慢→靜止
( 再回到第一步驟 )
0 ~ 255
0 ~ 255
卓爾榮譽學會創客工作坊 2018
int L1=7, L2=6, R1=5, R2=4;
void setup() {
pinMode(L1, OUTPUT);
pinMode(L2, OUTPUT);
pinMode(R1, OUTPUT);
pinMode(R2, OUTPUT);
}
void loop() {
analogWrite(L1, 255);
analogWrite(L2, 0);
analogWrite(R1, 255);
analogWrite(R2, 0);
}
挑戰:
讓車子用50%的速度
前進一秒,停下一秒,
後退一秒,停下一秒,
左旋一秒,停下一秒,
右旋一秒,停下一秒,
然後重複
卓爾榮譽學會創客工作坊 2018
有沒有更方便的寫法? (advanced)
› >> function ( 自訂函式 ) <<
› delay()、digitalWrite()
› setup()、 loop()
. . .
void loop() {
analogWrite(L1, 127);
analogWrite(L2, 0);
analogWrite(R1, 127);
analogWrite(R2, 0);
delay(1000);
analogWrite(L1, 0);
analogWrite(L2, 0);
analogWrite(R1, 0);
analogWrite(R2, 0);
delay(1000);
analogWrite(L1, 0);
analogWrite(L2, 127);
analogWrite(R1, 127);
analogWrite(R2, 0);
delay(1000);
. . .
}
void Left_Forward(){
analogWrite(L1, 127);
analogWrite(L2, 0);
}
// 我們叫它引數or參數
void Left_Forward2(int Power){
analogWrite(L1, Power);
analogWrite(L2, 0);
}
Left_Forward();Left_Forward2(127);
Left_Forward2(0);
Right_Forward2(127);
Right_Forward2(0);
卓爾榮譽學會創客工作坊 2018
練習 (advanced.)
›請大家試著把自己的程式碼中
馬達控制的部分以Function改寫
Hint :
一個輪子可能需要
一個forward、一個backward
共兩個function
來控制前轉和後轉
Thinking : 有沒有只寫一個function的方法?
void Left_Forward(){
analogWrite(L1, 127);
analogWrite(L2, 0);
}
void Left_Forward2(int Power){
analogWrite(L1, Power);
analogWrite(L2, 0);
}
卓爾榮譽學會創客工作坊 2018
. . .
void loop() {
analogWrite(L1, 127);
analogWrite(L2, 0);
analogWrite(R1, 127);
analogWrite(R2, 0);
delay(1000);
analogWrite(L1, 0);
analogWrite(L2, 0);
analogWrite(R1, 0);
analogWrite(R2, 0);
delay(1000);
analogWrite(L1, 0);
analogWrite(L2, 127);
analogWrite(R1, 127);
analogWrite(R2, 0);
delay(1000);
. . .
}
. . .
void loop() {
Left_Forward2(127);
Right_Forward2(0);
delay(1000);
Left_Forward2(0);
Right_Forward2(0);
delay(1000);
Left_Backward2(127);
Right_Forward2(127);
delay(1000);
. . .
}
卓爾榮譽學會創客工作坊 2018
練習 (advanced)
›試著放入兩個引數,
把forward、backward
併成一個副程式
void Left_Forward2(int Power){
analogWrite(L1, Power);
analogWrite(L2, 0);
}
void Left_Wheel(int direction, int Power){
}
卓爾榮譽學會創客工作坊 2018
讀取感測器
› digitalRead(pin);
pinMode( pin, OUTPUT );
卓爾榮譽學會創客工作坊 2018
練習題
›使用一個LED和一個碰撞感測器,若碰撞感測器被
按下則點亮LED,否則熄滅LED。
›調校紅外線感測器的感測距離,並試著用紅外線感
測器做到一樣的事情
›digitalRead()
卓爾榮譽學會創客工作坊 2018
將感測器的值顯示在螢幕上
void setup{
…
Serial.begin(9600);
…
}
void loop{
…
Serial.println(digitalRead(2));
…
}
卓爾榮譽學會創客工作坊 2018
將輪速控制融合感測器!
void loop(){
analogWrite(L1, 127);
analogWrite(L2, 0);
analogWrite(R1, 127);
analogWrite(R2, 0);
delay(1000);
}
void loop(){
analogWrite(L1, 127);
analogWrite(L2, 0);
analogWrite(R1, 127);
analogWrite(R2, 0);
if(analogRead(2)==0){ // 偵測到前面有東西
analogWrite(L1, 0); // 速度變0,車子停下
analogWrite(R1, 0); // 速度變0,車子停下
}
else{ // 速度變回127
analogWrite(L1, 127);
analogWrite(R1, 127);
}
delay(100);
}
卓爾榮譽學會創客工作坊 2018
練習!
›讓車子一直往前走,當前方遇到障礙物時
車子往後退,若後方碰撞感測器感測到障
礙物時再繼續往前進。
卓爾榮譽學會創客工作坊 2018
許修瑋
showay29@gmail.com
THE END

More Related Content

Recently uploaded

1.1.3急救你必须懂四年级设计与工艺练习活页练习单元一四年级设计与工艺急救你必须懂
1.1.3急救你必须懂四年级设计与工艺练习活页练习单元一四年级设计与工艺急救你必须懂1.1.3急救你必须懂四年级设计与工艺练习活页练习单元一四年级设计与工艺急救你必须懂
1.1.3急救你必须懂四年级设计与工艺练习活页练习单元一四年级设计与工艺急救你必须懂PUAXINYEEMoe
 
啟思中國語文 - 中二 單元一 - 孟嘗君列傳 - 記敍的方法和人稱1.pptx
啟思中國語文 - 中二 單元一 - 孟嘗君列傳 - 記敍的方法和人稱1.pptx啟思中國語文 - 中二 單元一 - 孟嘗君列傳 - 記敍的方法和人稱1.pptx
啟思中國語文 - 中二 單元一 - 孟嘗君列傳 - 記敍的方法和人稱1.pptxbusinesshealthwise
 
1.🎉“黑客”如何修改成绩?🤔🎉 在这个信息爆炸的时代,我们经常会看到各种作弊手段。但是你知道吗?有一种作弊方式可能比你想象中更巧妙:它就是——黑客![单...
1.🎉“黑客”如何修改成绩?🤔🎉 在这个信息爆炸的时代,我们经常会看到各种作弊手段。但是你知道吗?有一种作弊方式可能比你想象中更巧妙:它就是——黑客![单...1.🎉“黑客”如何修改成绩?🤔🎉 在这个信息爆炸的时代,我们经常会看到各种作弊手段。但是你知道吗?有一种作弊方式可能比你想象中更巧妙:它就是——黑客![单...
1.🎉“黑客”如何修改成绩?🤔🎉 在这个信息爆炸的时代,我们经常会看到各种作弊手段。但是你知道吗?有一种作弊方式可能比你想象中更巧妙:它就是——黑客![单...微信 tytyqqww业务接单
 
taibif_資料標準概念介紹_20240509_20240509_20340509.pdf
taibif_資料標準概念介紹_20240509_20240509_20340509.pdftaibif_資料標準概念介紹_20240509_20240509_20340509.pdf
taibif_資料標準概念介紹_20240509_20240509_20340509.pdfjhujyunjhang
 
taibif_開放資料流程-清理資料01-通則_20240509_20240509.pdf
taibif_開放資料流程-清理資料01-通則_20240509_20240509.pdftaibif_開放資料流程-清理資料01-通則_20240509_20240509.pdf
taibif_開放資料流程-清理資料01-通則_20240509_20240509.pdfjhujyunjhang
 
永久可查英国北安普顿大学毕业证(uom学位证书)电子版学位证书留服认证原版一模一样
永久可查英国北安普顿大学毕业证(uom学位证书)电子版学位证书留服认证原版一模一样永久可查英国北安普顿大学毕业证(uom学位证书)电子版学位证书留服认证原版一模一样
永久可查英国北安普顿大学毕业证(uom学位证书)电子版学位证书留服认证原版一模一样yuhpu
 
Math Chapter3-教學PPT第03單元形體關係、體積與表面積Grade Six
Math Chapter3-教學PPT第03單元形體關係、體積與表面積Grade SixMath Chapter3-教學PPT第03單元形體關係、體積與表面積Grade Six
Math Chapter3-教學PPT第03單元形體關係、體積與表面積Grade Six611002610
 
1.🎉成绩单,你的成绩! 💡🔥每个人都有自己的成绩单,它记录着我们努力的成果。但有时候,看着这些数字,却发现它们好像在嘲笑我?别担心,让我来告诉你们怎么改...
1.🎉成绩单,你的成绩! 💡🔥每个人都有自己的成绩单,它记录着我们努力的成果。但有时候,看着这些数字,却发现它们好像在嘲笑我?别担心,让我来告诉你们怎么改...1.🎉成绩单,你的成绩! 💡🔥每个人都有自己的成绩单,它记录着我们努力的成果。但有时候,看着这些数字,却发现它们好像在嘲笑我?别担心,让我来告诉你们怎么改...
1.🎉成绩单,你的成绩! 💡🔥每个人都有自己的成绩单,它记录着我们努力的成果。但有时候,看着这些数字,却发现它们好像在嘲笑我?别担心,让我来告诉你们怎么改...微信 tytyqqww业务接单
 
法国蒙彼利埃国家高等建筑学院毕业证制作/德语歌德B1证书/加拿大新斯科舍省农业学院文凭加急制作一个
法国蒙彼利埃国家高等建筑学院毕业证制作/德语歌德B1证书/加拿大新斯科舍省农业学院文凭加急制作一个法国蒙彼利埃国家高等建筑学院毕业证制作/德语歌德B1证书/加拿大新斯科舍省农业学院文凭加急制作一个
法国蒙彼利埃国家高等建筑学院毕业证制作/德语歌德B1证书/加拿大新斯科舍省农业学院文凭加急制作一个michaelell902
 
10.2.1 马来西亚各州名称的由来六年级历史单元练习马来西亚各州名称的由来练习
10.2.1 马来西亚各州名称的由来六年级历史单元练习马来西亚各州名称的由来练习10.2.1 马来西亚各州名称的由来六年级历史单元练习马来西亚各州名称的由来练习
10.2.1 马来西亚各州名称的由来六年级历史单元练习马来西亚各州名称的由来练习PUAXINYEEMoe
 

Recently uploaded (10)

1.1.3急救你必须懂四年级设计与工艺练习活页练习单元一四年级设计与工艺急救你必须懂
1.1.3急救你必须懂四年级设计与工艺练习活页练习单元一四年级设计与工艺急救你必须懂1.1.3急救你必须懂四年级设计与工艺练习活页练习单元一四年级设计与工艺急救你必须懂
1.1.3急救你必须懂四年级设计与工艺练习活页练习单元一四年级设计与工艺急救你必须懂
 
啟思中國語文 - 中二 單元一 - 孟嘗君列傳 - 記敍的方法和人稱1.pptx
啟思中國語文 - 中二 單元一 - 孟嘗君列傳 - 記敍的方法和人稱1.pptx啟思中國語文 - 中二 單元一 - 孟嘗君列傳 - 記敍的方法和人稱1.pptx
啟思中國語文 - 中二 單元一 - 孟嘗君列傳 - 記敍的方法和人稱1.pptx
 
1.🎉“黑客”如何修改成绩?🤔🎉 在这个信息爆炸的时代,我们经常会看到各种作弊手段。但是你知道吗?有一种作弊方式可能比你想象中更巧妙:它就是——黑客![单...
1.🎉“黑客”如何修改成绩?🤔🎉 在这个信息爆炸的时代,我们经常会看到各种作弊手段。但是你知道吗?有一种作弊方式可能比你想象中更巧妙:它就是——黑客![单...1.🎉“黑客”如何修改成绩?🤔🎉 在这个信息爆炸的时代,我们经常会看到各种作弊手段。但是你知道吗?有一种作弊方式可能比你想象中更巧妙:它就是——黑客![单...
1.🎉“黑客”如何修改成绩?🤔🎉 在这个信息爆炸的时代,我们经常会看到各种作弊手段。但是你知道吗?有一种作弊方式可能比你想象中更巧妙:它就是——黑客![单...
 
taibif_資料標準概念介紹_20240509_20240509_20340509.pdf
taibif_資料標準概念介紹_20240509_20240509_20340509.pdftaibif_資料標準概念介紹_20240509_20240509_20340509.pdf
taibif_資料標準概念介紹_20240509_20240509_20340509.pdf
 
taibif_開放資料流程-清理資料01-通則_20240509_20240509.pdf
taibif_開放資料流程-清理資料01-通則_20240509_20240509.pdftaibif_開放資料流程-清理資料01-通則_20240509_20240509.pdf
taibif_開放資料流程-清理資料01-通則_20240509_20240509.pdf
 
永久可查英国北安普顿大学毕业证(uom学位证书)电子版学位证书留服认证原版一模一样
永久可查英国北安普顿大学毕业证(uom学位证书)电子版学位证书留服认证原版一模一样永久可查英国北安普顿大学毕业证(uom学位证书)电子版学位证书留服认证原版一模一样
永久可查英国北安普顿大学毕业证(uom学位证书)电子版学位证书留服认证原版一模一样
 
Math Chapter3-教學PPT第03單元形體關係、體積與表面積Grade Six
Math Chapter3-教學PPT第03單元形體關係、體積與表面積Grade SixMath Chapter3-教學PPT第03單元形體關係、體積與表面積Grade Six
Math Chapter3-教學PPT第03單元形體關係、體積與表面積Grade Six
 
1.🎉成绩单,你的成绩! 💡🔥每个人都有自己的成绩单,它记录着我们努力的成果。但有时候,看着这些数字,却发现它们好像在嘲笑我?别担心,让我来告诉你们怎么改...
1.🎉成绩单,你的成绩! 💡🔥每个人都有自己的成绩单,它记录着我们努力的成果。但有时候,看着这些数字,却发现它们好像在嘲笑我?别担心,让我来告诉你们怎么改...1.🎉成绩单,你的成绩! 💡🔥每个人都有自己的成绩单,它记录着我们努力的成果。但有时候,看着这些数字,却发现它们好像在嘲笑我?别担心,让我来告诉你们怎么改...
1.🎉成绩单,你的成绩! 💡🔥每个人都有自己的成绩单,它记录着我们努力的成果。但有时候,看着这些数字,却发现它们好像在嘲笑我?别担心,让我来告诉你们怎么改...
 
法国蒙彼利埃国家高等建筑学院毕业证制作/德语歌德B1证书/加拿大新斯科舍省农业学院文凭加急制作一个
法国蒙彼利埃国家高等建筑学院毕业证制作/德语歌德B1证书/加拿大新斯科舍省农业学院文凭加急制作一个法国蒙彼利埃国家高等建筑学院毕业证制作/德语歌德B1证书/加拿大新斯科舍省农业学院文凭加急制作一个
法国蒙彼利埃国家高等建筑学院毕业证制作/德语歌德B1证书/加拿大新斯科舍省农业学院文凭加急制作一个
 
10.2.1 马来西亚各州名称的由来六年级历史单元练习马来西亚各州名称的由来练习
10.2.1 马来西亚各州名称的由来六年级历史单元练习马来西亚各州名称的由来练习10.2.1 马来西亚各州名称的由来六年级历史单元练习马来西亚各州名称的由来练习
10.2.1 马来西亚各州名称的由来六年级历史单元练习马来西亚各州名称的由来练习
 

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Week5 驅動程式

Editor's Notes

  1. 確認學員都有可變電阻、LED
  2. 要提到digitalWrite, analogWrite 要pinMode
  3. 記得要家電阻
  4. 不知道大家還記不記得第一堂課的時候就有PO過這張圖 App的部分是後面的課程,我們先暫時把它放到一邊 ( 按 ) 現在我們的目標就是要讓車子動起來 所以就需要寫到控制程式 但是也不是沒有目的的動,而是要讓他依照我們想要的方式動 那現在我們要先來學怎麼讓輪子動起來 那輪子要動起來的話自然需要讓馬達開始轉 (按)
  5. 我們用的馬達叫做直流馬達(按),其他還有伺服馬達、步進馬達、無刷馬達等很多不同的馬達類型 那直流馬達要怎麼驅動呢?很簡單,它上面有兩個接點(按),如果我們給他們電位差,它就會開始轉 那為了方便說明,我們先把他們叫做(按)小A跟小B吧 那我們可以看到(按) 後略
  6. 那我們著自走車有兩個可以控制的馬達(按) 所以根據上一頁說的,一個馬達要有AB兩個點來控制 那兩個馬達就有(按)四個點 (按) 要四個輸出才能控制兩個輪子的正反轉
  7. 那我們來稍微模擬一下這四個輸出點的情況跟車子會做什麼動作(按) 後略
  8. 好 現在請大家把車子上的這塊驅動版找出來 它是一塊驅動直流馬達的模組,我們從7688輸出類比的訊號以後,他會幫我們傳到馬達裡面 那可能有人會想說為什麼不知接讓7688連接到馬達,還要透過這個板子呢? 那是因為直流馬達要動的話需要比較大的電流 我們的7688上面的腳位沒有辦法輸出足夠大的電流讓車子可以跑 所以需要透過馬達驅動版,把外接電池的電力送到馬達上
  9. 好,那大家應該還記得剛剛說的這個表格 (按) 那上面的ABCD就可以對應到馬達控制板上的這四個腳位(按) (按) 我們注意到in1 跟in2是控制左輪,in3 in4是控制右輪的 所以如果我們在in1輸入5伏特,in2輸入0伏特,那左輪就會開始轉。 現在我們把他們接到7688上面去 所以就會是這樣的對應 那接好後我們就可以用analogWrite去控制這些輸出了 (按下業)
  10. 所以大概我們就可以把程式寫成這樣 請大家現在先照著這樣做 (練習5分鐘)
  11. 那可能有人比較厲害,會記得我們之前說過的宣告變數 這樣如果發現輪子方向轉反了,只要把上面L1跟L2的值換過來就好 那現在,請大家試著加入for迴圈
  12. 車子用50%的速度 前進一秒,停下一秒, 後退一秒,停下一秒, 左旋一秒,停下一秒, 右旋一秒,停下一秒, 然後重複 好,可能會有人發現這樣我們每次要控制輪子做一件事情的時候都要寫四行程式碼,那 (按)
  13. 我們原本寫出來的程式應該會長這樣 (按) 現在要教一個新的東西叫做(按)副程式 或是叫做自訂函式 大家可以把它想像成把過度重複的程式碼濃縮起來 (按)像我們在寫delay的時候程式跑到這邊就會幫我們停下來我們指定的毫秒數嘛 那digitalWrite也是,會幫我們在指定的腳位輸出指定的電壓值 這些看起來很簡單的程式碼其實是默默的幫我們做了很多事情 (按) 另外我們每次都會寫的setup跟loop也是副程式,只是他們比較特別 (略) 那現在我們要做的呢,就是自己定義函式,讓重複的東西可以用一行程式碼取代 定義的方法要這樣寫 (按) (略) 那特別要注意的是我們要把(按)副程式定義在其他副程式的外面 然後當我們需要用到的時候,就可以直接把副程式打在loop裡面 像是這樣(按) 或是加入參數的方法(按)
  14. 介紹碰撞感測器,請學員拿出碰撞感測器讀懂上面的接腳 提醒設置pinMode
  15. 還記不記得剛剛有說,碰撞感測器按下的時候會傳回零,不按的時候傳回一,那除了覺得我應該不會騙你以外有什麼方法可以證實這是對的? 或是我們在用analogRead讀取可變電阻的值時,怎麼知道他是在哪個範圍裏面變動或是我們怎麼知道我們現在轉到這樣以後他的數值是多少? ( 換頁 )
  16. 我們可以用這兩行 (按) 簡單的語法把數值印在螢幕上 然後大家可以看到這邊的ln (按),她是換行的意思,如果你輸出後不想換行的話,可以把ln去掉 那請大家現在花五分鐘的時間試試看碰撞感測器或是紅外線感測器 (練習五分鐘) 那我們可以看到,Serial.println() 這個東西也是一個函式, 我們把要輸出的東西當成引數丟進去,然後她會幫我們做出印在螢幕上這件事情 好 那為什麼我們要教怎麼讀取感測器呢?