發表文章

目前顯示的是 4月, 2018的文章

Scratch 遊戲:太鼓達人

圖片
若您覺得文章寫得不錯,請點選文章上的廣告,來支持小編,謝謝。 太鼓達人 原是一款街機遊戲,玩家配合音樂的節奏來敲打機台上的鼓。隨後很多遊戲機也推出家用版。筆者根據這款遊戲設計出底下的小遊戲來模擬( https://scratch.mit.edu/projects/218261374/ ): 設計方式: 1. 新增一個箭頭角色,使用內建的箭頭造型。 筆者會使用這裡的造型標號來做程式的設計,也就是 造型編號1為向左箭頭; 造型編號2為向右箭頭; 造型編號3為向下箭頭; 造型編號4為向上箭頭。 2. 新增鼓的角色,並設計四種造型 造型編號1為未打下鼓的造型; 造型編號2為打下鼓的造型; 造型編號3為得分的造型; 造型編號4為失誤的造型。 3. 程式設計部分有使用到分身、廣播、自訂函式積木等觀念。基本想法是產生箭頭的分身,並隨機選擇箭頭的造型,若箭頭與鼓的距離小於40且按下正確的鍵盤按鍵時,玩家就會獲得一分,箭頭分身就會被刪除。 4. 箭頭角色的積木程式 5. 鼓角色的積木程式 延伸練習: 如何增加遊戲的難度?例如: 1. 當分數超過100時,箭頭移動的速度就增加。 2. 玩家只能失誤3次,失誤3次遊戲就結束。 3. 不同的得分方式,當箭頭在鼓的正中央(靶心)時為Perfect的得分,其餘皆為一般Good得分。

Tinkercad Circuits:LED閃爍 (LED Blink )

圖片
若您覺得文章寫得不錯,請點選文章上的廣告,來支持小編,謝謝。 If you like this post, please click the ads on the blog or  buy me a coffee . Thank you very much. 本文要使用線上的Arduino模擬環境來示範 LED 閃爍,並說明積木程式產生出來的Arduino C語言之間的對應關係。This tutorial will teach the reader to use Tinkcercad circuits  designing a LED blinking project. And illustrate the relationships between the blocks and C code. 材料(Materials): Arduino UNO R3 x 1 LED x 1 220 ohm Resistor x 1 Small Breadboard x 1 電路(Circuit): LED blinking without breadboard LED blinking with breadboard The LED anode is connected to Arduino UNO pin 13. The LED cathode is connected to Arduino UNO ground. 程式碼(The Code): 上圖左邊是積木程式,右邊是 Arduino C 語言。舉例來說,左邊的 set built-in LED to HIGH 積木所對應的C語言為 digitalWrite(13, HIGH),wait 1 secs 對應的是 delay(1000)。也就是左邊的四個積木所對應的C語言程式碼是在右邊的 void loop() { .... } 裡。 The left side of the image is blocks and the right side of the image is Arduino C. For example, "set built-in LED to HIGH" is mapped to "digitalWrite(...

Tinkercad Circuits:簡易電路 LED 兩端不接地(Light up a LED without connecting the ground)

圖片
若您覺得文章寫得不錯,請點選文章上的廣告,來支持小編,謝謝。 If you like this post, please click the ads on the blog or  buy me a coffee . Thank you very much. 透過此簡易的電路設計,可以了解到電壓與LED亮度之間的關係。 In this simple circuit, the reader can learn the relationship between the voltage and LED brightness. 材料(Materials): 1.5V battery x (from 2 to 5) LED x 1 電路(Circuit): 上圖右方是LED正極的電壓;上圖左方是LED負極的電壓。 The right side is the voltage applied to LED anode. The left side is the voltage applied to LED cathode. 我們可以做底下的實驗(The Experiments): 讓正負極的電壓相同。(The voltage between anode and cathode is equal.) 讓正極的電壓大於負極。(The anode voltage is higher than the cathode voltage.) 讓正極的電壓小於負極。(The anode voltage is lower than the cathode voltage.) 進行實驗時,請觀察LED的亮度與正負極電壓之間的關係。 Please observe the relationship between the voltage and LED brightness during the experiment. 示範影片(Demo Video): 範例連結(Example Link): https://www.tinkercad.com/things/9H5rd83QEir-led-#/

mBlock 單元二十一:打地鼠模擬

圖片
若您覺得文章寫得不錯,請點選文章上的廣告,來支持小編,謝謝。 在 Webduino 模擬器:打地鼠 一文中,筆者使用模擬器來模擬打地鼠,卻沒有實際硬體可以玩,所以本文將使用mBlock打造Arduino版的打地鼠。 硬體材料(Materials): Arduino UNO R3 板子 x 1 公對公杜邦線 x 14 公對母杜邦線 x 6 麵包板 x 1 蜂鳴器 x 1 I2C LCD x 1 四腳按鈕 x 4 LED x 4 1K 電阻 x 5 接線對應腳位 : 蜂鳴器接 D12 LCD SDA 接 A4 LCD SCL 接 A5 按鈕分別接 D3、D5、D7、D9 LED分別接 D2、D4、D6、D8 完成圖(The finished assembling): mBlock I2C LCD 擴展 要讓 mBlock 可以使用 I2C LCD 的積木,需在 mBlock中,開啟 擴展管理員 安裝擴展  LCD I2C Pack 1.03 。並將  NewLiquidCrystal  (本文使用 NewliquidCrystal_1.3.4.zip )解壓縮後,複製到mBlock 的 Arduino 程式庫路徑  C:\Program Files (x86)\mBlock\Arduino\libraries  。 在計分方面,筆者設計 當分數越高時,分數加越多 LED等待時間會 隨著分數越高,時間越短 示範影片: 程式範例可在此下載 。

STEMbot提供的新版 Otto 程式

圖片
若您覺得文章寫得不錯,請點選文章上的廣告,來支持小編,謝謝。 stembotvn 這越南公司 有提供不一樣的 Otto 程式,可以不用將藍芽的斷開就可以直接燒錄程式,也提供更多的功能。程式網址: https://github.com/stembotvn/OttoDIY_Vbot 不過接線方式和 Otto 官方的不太一樣,接線說明( 紅字為不同處 )如下: 硬體組件 Nano腳位 Servo Hip left D2 Servo Foot Left D4 Servo Hip right D3 Servo Foot right D5 Buzzer D13 Bluetooth HC06 Rx D7 Bluetooth HC06 Tx D6 SRF04 Trigger D8 SRF04 Echo D9 Max7219 LedMatrix Data D10 Max7219 LedMatrix CS D11 Max7219 LedMatrix Clk D12 Analog Sound Sensor Module A6 Button 1 A2 Button 2 A3 Light sensor Module (RIGHT) Analog output Pin A0 Light Sensor Module (LEFT) Analog output Pin A1 下圖取至 https://github.com/stembotvn/OttoDIY_Vbot 筆者發現只要將Buzzer的腳位從 D10 換成 D13 就可以使用STEMbot的程式,但沒有Otto官方的smooth_criminal範例程式,於是筆者將 smooth_criminal 的範例加到專案裡, 讀者可在此下載 。 程式安裝的安裝方式如下: 從 Arduino IDE 的 草稿碼 ==> 匯入程式庫 ==> 加入.ZIP程式庫 ==> 選擇【OttoDIY_Vbot.zip】 檔案 開啟STEMbot的範例(以避障Otto_avoid為例): 從 Arduino IDE 的 檔案 ==> 範例 OttoDIY_Vbot ==> OTTO_avoid 選擇板子 arduino ...