實驗參考網址
CH3
CH4
CH5
http://pub.tust.edu.tw/mechanic/mclab/public_html/_private/electronics/diode/circuit.htm
電子學實驗
DHT12 溫度.濕度感測器
https://yhhuang1966.blogspot.com/2015/08/arduino-dht11.html
https://github.com/Bobadas/DHT12_library_Arduino
/*
* 2018.06.12
* 按照DHP11接角位
* 左1 3V
* 左2 D0
* 左3 空
* 左4 GND
*/
#include "DHT.h"
#define DHTPIN D0
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
Serial.println("DHT11 test!");
dht.begin();
}
void loop() {
delay(1000);
float h = dht.readHumidity();
float t = dht.readTemperature();
float f = dht.readTemperature(true);
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Serial.print("濕度: ");
Serial.print(h);
Serial.print("%\t");
Serial.print("溫度: ");
Serial.print(t);
Serial.print("*C\t");
Serial.println(" ");
}
https://github.com/Bobadas/DHT12_library_Arduino
/*
* 2018.06.12
* 按照DHP11接角位
* 左1 3V
* 左2 D0
* 左3 空
* 左4 GND
*/
#include "DHT.h"
#define DHTPIN D0
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
Serial.println("DHT11 test!");
dht.begin();
}
void loop() {
delay(1000);
float h = dht.readHumidity();
float t = dht.readTemperature();
float f = dht.readTemperature(true);
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Serial.print("濕度: ");
Serial.print(h);
Serial.print("%\t");
Serial.print("溫度: ");
Serial.print(t);
Serial.print("*C\t");
Serial.println(" ");
}
Blynk 期末
http://wyj-learning.blogspot.tw/2018/01/arduino-04-blynk-arduino.html
https://dooit.com.tw/tutorials/nodemcu%E6%90%96%E6%8E%A7%E9%A4%B5%E9%AD%9A%E7%A5%9E%E5%99%A8/
https://examples.blynk.cc/?board=NodeMCU&shield=ESP8266%20WiFi&example=GettingStarted%2FServo
https://www.youtube.com/watch?v=4zbGkqEK70k
http://yhhuang1966.blogspot.com/2016/08/blynk-displays.html
http://docs.blynk.cc/#widgets-displays-labeled-value
https://www.taiwansensor.com.tw/shop/sensors/env/tprh/dht12-%E6%95%B8%E5%AD%97%E6%BA%AB%E6%BF%95%E5%BA%A6%E6%84%9F%E6%B8%AC%E5%99%A8%E6%A8%A1%E7%B5%84-%E5%96%AE%E7%B8%BD%E7%B7%9A-%E5%92%8C-i2c-%E9%80%9A%E4%BF%A1-dht11%E5%8D%87%E7%B4%9A%E7%89%88/
草稿碼 , 匯入程式庫 , 管理程式庫 , 搜索Blynk , 選擇0.5.3
https://community.blynk.cc/t/blynk-virtual-pin-blynk-write/7001/3
blynk 虛擬腳位
ef13a7aefb074f5e98833f3ac24e82 e3 text
ESP_0016F3
https://dooit.com.tw/tutorials/nodemcu%E6%90%96%E6%8E%A7%E9%A4%B5%E9%AD%9A%E7%A5%9E%E5%99%A8/
https://examples.blynk.cc/?board=NodeMCU&shield=ESP8266%20WiFi&example=GettingStarted%2FServo
https://www.youtube.com/watch?v=4zbGkqEK70k
http://yhhuang1966.blogspot.com/2016/08/blynk-displays.html
http://docs.blynk.cc/#widgets-displays-labeled-value
https://www.taiwansensor.com.tw/shop/sensors/env/tprh/dht12-%E6%95%B8%E5%AD%97%E6%BA%AB%E6%BF%95%E5%BA%A6%E6%84%9F%E6%B8%AC%E5%99%A8%E6%A8%A1%E7%B5%84-%E5%96%AE%E7%B8%BD%E7%B7%9A-%E5%92%8C-i2c-%E9%80%9A%E4%BF%A1-dht11%E5%8D%87%E7%B4%9A%E7%89%88/
草稿碼 , 匯入程式庫 , 管理程式庫 , 搜索Blynk , 選擇0.5.3
https://community.blynk.cc/t/blynk-virtual-pin-blynk-write/7001/3
blynk 虛擬腳位
ef13a7aefb074f5e98833f3ac24e82
ESP_0016F3
烙鐵的保養 && 焊錫使用
http://subig1957.pixnet.net/blog/post/17151058-%E7%84%8A%E9%8C%AB%E8%88%87%E5%8E%BB%E9%8C%AB%E6%BC%AB%E8%AB%87
https://www.mobile01.com/topicdetail.php?f=168&t=5053888
https://www.strongpilab.com/iron-solder-desolder-skill/
https://www.mobile01.com/topicdetail.php?f=116&t=5157858
http://musicalsound.com.tw/diy/solder.htm
http://www.hitonaudio.com/forum_oneissue.php?mi=366&page=3
http://subig1957.pixnet.net/blog/post/17151058-%E7%84%8A%E9%8C%AB%E8%88%87%E5%8E%BB%E9%8C%AB%E6%BC%AB%E8%AB%87
錫聲 && 音響電容
https://www.mobile01.com/topicdetail.php?f=168&t=5053888
https://www.strongpilab.com/iron-solder-desolder-skill/
https://www.mobile01.com/topicdetail.php?f=116&t=5157858
http://musicalsound.com.tw/diy/solder.htm
http://www.hitonaudio.com/forum_oneissue.php?mi=366&page=3
http://subig1957.pixnet.net/blog/post/17151058-%E7%84%8A%E9%8C%AB%E8%88%87%E5%8E%BB%E9%8C%AB%E6%BC%AB%E8%AB%87
錫聲 && 音響電容
SG90 馬達
#include <Servo.h>
Servo myservo;
void setup()
{
myservo.attach(D7,500,2400);
}
void loop()
{
for(int i = 0; i <= 180; i+=1){
myservo.write(i);
delay(15);
}
for(int i = 180; i >= 0; i-=1){
myservo.write(i);
delay(15);
}
}
//紅接UV
//橘接D7
//咖啡接GND
Servo myservo;
void setup()
{
myservo.attach(D7,500,2400);
}
void loop()
{
for(int i = 0; i <= 180; i+=1){
myservo.write(i);
delay(15);
}
for(int i = 180; i >= 0; i-=1){
myservo.write(i);
delay(15);
}
}
//紅接UV
//橘接D7
//咖啡接GND
光敏電阻 && 可變電阻
const byte potpin = A0;
int val; //接收類比輸入值的變數,類行為整數
//可變電阻輸出範圍值 0~1023
void setup() {
Serial.begin(9600); // 以9600bps速率初始化序列錐
}
void loop() {
val = analogRead(potpin);
Serial.println(val);
delay(500);
}
http://mcu-tw.blogspot.com/2013/06/arduino-lab-5-led.html
http://coopermaa2nd.blogspot.tw/2010/12/arduino-lab4.html
int val; //接收類比輸入值的變數,類行為整數
//可變電阻輸出範圍值 0~1023
void setup() {
Serial.begin(9600); // 以9600bps速率初始化序列錐
}
void loop() {
val = analogRead(potpin);
Serial.println(val);
delay(500);
}
http://mcu-tw.blogspot.com/2013/06/arduino-lab-5-led.html
http://coopermaa2nd.blogspot.tw/2010/12/arduino-lab4.html
音樂音量led顯示
// 先用Arduino做 ,之後再找晶片
// https://item.jd.com/24364670781.html
//https://www.banggood.com/With-Housing-DIY-Music-Spectrum-LED-Flash-Kit-DIY-Amplifier-Speaker-Kit-p-986043.html?utm_source=youtube&utm_medium=CreativeChannel&utm_campaign=Nov&utm_content=huangwenjie&cur_warehouse=CN
const byte potPin = A0;
const byte pins[6] = {D3, D2, D4, D5, D6, D0 };
int val;
int k;
void setup() {
Serial.begin(9600);
pinMode(D0, OUTPUT);
pinMode(D2, OUTPUT);
pinMode(D3, OUTPUT);
pinMode(D4, OUTPUT);
pinMode(D5, OUTPUT);
pinMode(D6, OUTPUT);
for (int thisPin = 0; thisPin < 6; thisPin++) {
pinMode(pins[thisPin], OUTPUT); }
}
void loop() {
val = analogRead(potPin);
Serial.print("val=");
Serial.println(val);
k = val/147; // 1024/7 = 147
Serial.print("val/147=");
Serial.println(k);
for (int thisPin = 0; thisPin < k; thisPin++) {
digitalWrite(pins[thisPin], HIGH); }
delay (100);
for (int thisPin = 0; thisPin < k; thisPin++) {
digitalWrite(pins[thisPin], LOW); }
}
// https://item.jd.com/24364670781.html
//https://www.banggood.com/With-Housing-DIY-Music-Spectrum-LED-Flash-Kit-DIY-Amplifier-Speaker-Kit-p-986043.html?utm_source=youtube&utm_medium=CreativeChannel&utm_campaign=Nov&utm_content=huangwenjie&cur_warehouse=CN
const byte potPin = A0;
const byte pins[6] = {D3, D2, D4, D5, D6, D0 };
int val;
int k;
void setup() {
Serial.begin(9600);
pinMode(D0, OUTPUT);
pinMode(D2, OUTPUT);
pinMode(D3, OUTPUT);
pinMode(D4, OUTPUT);
pinMode(D5, OUTPUT);
pinMode(D6, OUTPUT);
for (int thisPin = 0; thisPin < 6; thisPin++) {
pinMode(pins[thisPin], OUTPUT); }
}
void loop() {
val = analogRead(potPin);
Serial.print("val=");
Serial.println(val);
k = val/147; // 1024/7 = 147
Serial.print("val/147=");
Serial.println(k);
for (int thisPin = 0; thisPin < k; thisPin++) {
digitalWrite(pins[thisPin], HIGH); }
delay (100);
for (int thisPin = 0; thisPin < k; thisPin++) {
digitalWrite(pins[thisPin], LOW); }
}
DIY . 電子玩具
https://will-123456.blogspot.tw/2017/06/linkit-7697-badge.html#links
https://www.techbang.com/posts/41902?from=popin
https://www.techbang.com/posts/49558?from=popin
https://www.techbang.com/posts/42760-mr-beam-ii-multi-function-laser-cutting-machine-at-home-can-easily-use
http://yhhuang1966.blogspot.tw/2017/08/arduino.html
https://cloud.wf8266.com/
https://www.techbang.com/posts/41902?from=popin
https://www.techbang.com/posts/49558?from=popin
https://www.techbang.com/posts/42760-mr-beam-ii-multi-function-laser-cutting-machine-at-home-can-easily-use
http://yhhuang1966.blogspot.tw/2017/08/arduino.html
https://cloud.wf8266.com/
HC - SR04 超音波測距 & 計算
/*聲音在空氣中的傳播速度大約是每秒 340 公尺,
傳播速度會受溫度影響,溫度愈高傳播速度愈快。
假設以 340 公尺計算,1000000 / 340 * 100 = 29.4 ms,四捨五入後,
可知聲音傳播 1 公分所需的時間為 29 microseconds (百萬分之一秒)。*/
// https://raspberrypi.readbook.tw/hcsr04.html
// http://lihan.shinyo.bixone.com/Arduino/arduino-2016.12.21.html
/* HC - SR04 接腳說明 :
* VCC : 輸入電壓5V 接到 VU 接腳
* Trig : 觸發腳,可共用GPIO接腳
* Echo : 接收腳,不可共用GPIO接腳
*/
int pins[7] = {D3,D2,D4,D5,D6,D0,D1};
boolean data[11][7] = {
1,1,1,1,1,1,0, // 0
0,1,1,0,0,0,0, // 1
1,1,0,1,1,0,1, // 2
1,1,1,1,0,0,1, // 3
0,1,1,0,0,1,1, // 4
1,0,1,1,0,1,1, // 5
1,0,1,1,1,1,1, // 6
1,1,1,0,0,1,0, // 7
1,1,1,1,1,1,1, // 8
1,1,1,1,0,1,1, // 9
0,0,0,0,0,0,0,}; // 10 ( off_all_LED )
void writeNumber(int n){ //把七段顯示器顯示函式獨立
for(int i = 0; i < 7; i++){
digitalWrite(pins[i], data[n][i] == HIGH);
}
}
const byte trig = D7; //觸發腳
const int echo = D8; //接收腳
unsigned long d;
unsigned long ping (){
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
return pulseIn (echo,HIGH); //I為大i
}
void setup(){
Serial.begin(9600);
pinMode(D0, OUTPUT);
pinMode(D1, OUTPUT);
pinMode(D2, OUTPUT);
pinMode(D3, OUTPUT);
pinMode(D4, OUTPUT);
pinMode(D5, OUTPUT);
pinMode(D6, OUTPUT);
pinMode(trig, OUTPUT);
pinMode(echo,INPUT);
}
int n;
void loop(){
d = ping() / 58.8 ;
Serial.print(d);
Serial.print("cm");
Serial.println( );
Serial.println(ping() );
if (d <= 18){
n = d / 2 ;
writeNumber(n+1);
}
delay(150);
}
傳播速度會受溫度影響,溫度愈高傳播速度愈快。
假設以 340 公尺計算,1000000 / 340 * 100 = 29.4 ms,四捨五入後,
可知聲音傳播 1 公分所需的時間為 29 microseconds (百萬分之一秒)。*/
// https://raspberrypi.readbook.tw/hcsr04.html
// http://lihan.shinyo.bixone.com/Arduino/arduino-2016.12.21.html
/* HC - SR04 接腳說明 :
* VCC : 輸入電壓5V 接到 VU 接腳
* Trig : 觸發腳,可共用GPIO接腳
* Echo : 接收腳,不可共用GPIO接腳
*/
int pins[7] = {D3,D2,D4,D5,D6,D0,D1};
boolean data[11][7] = {
1,1,1,1,1,1,0, // 0
0,1,1,0,0,0,0, // 1
1,1,0,1,1,0,1, // 2
1,1,1,1,0,0,1, // 3
0,1,1,0,0,1,1, // 4
1,0,1,1,0,1,1, // 5
1,0,1,1,1,1,1, // 6
1,1,1,0,0,1,0, // 7
1,1,1,1,1,1,1, // 8
1,1,1,1,0,1,1, // 9
0,0,0,0,0,0,0,}; // 10 ( off_all_LED )
void writeNumber(int n){ //把七段顯示器顯示函式獨立
for(int i = 0; i < 7; i++){
digitalWrite(pins[i], data[n][i] == HIGH);
}
}
const byte trig = D7; //觸發腳
const int echo = D8; //接收腳
unsigned long d;
unsigned long ping (){
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
return pulseIn (echo,HIGH); //I為大i
}
void setup(){
Serial.begin(9600);
pinMode(D0, OUTPUT);
pinMode(D1, OUTPUT);
pinMode(D2, OUTPUT);
pinMode(D3, OUTPUT);
pinMode(D4, OUTPUT);
pinMode(D5, OUTPUT);
pinMode(D6, OUTPUT);
pinMode(trig, OUTPUT);
pinMode(echo,INPUT);
}
int n;
void loop(){
d = ping() / 58.8 ;
Serial.print(d);
Serial.print("cm");
Serial.println( );
Serial.println(ping() );
if (d <= 18){
n = d / 2 ;
writeNumber(n+1);
}
delay(150);
}
Arduino - 期中考
/* 期中考 :
* 有B.C兩顆按鈕,兩顆沒有按下時,
* 0~9循環(A迴圈),
* 按下B時,亂數K,顯示K,直到按下C
* 按下C時,如果K是0~5,向左三圈
* 如果K是6~9,向右三圈
* 然後繼續循換0~9
*/
int pins[7] = {D3,D2,D4,D5,D6,D0,D1};
const boolean data[11][7] = {
1,1,1,1,1,1,0, // 0
0,1,1,0,0,0,0, // 1
1,1,0,1,1,0,1, // 2
1,1,1,1,0,0,1, // 3
0,1,1,0,0,1,1, // 4
1,0,1,1,0,1,1, // 5
1,0,1,1,1,1,1, // 6
1,1,1,0,0,1,0, // 7
1,1,1,1,1,1,1, // 8
1,1,1,1,0,1,1, // 9
0,0,0,0,0,0,0, }; // 10 ( off_all_LED )
void writeNumber(int n){ //把七段顯示器顯示函式獨立
for(int i = 0; i < 7; i++){
digitalWrite(pins[i], data[n][i] == HIGH);
} }
void setup(){
Serial.begin(9600);
pinMode(D0,OUTPUT);
pinMode(D1,OUTPUT);
pinMode(D2,OUTPUT);
pinMode(D3,OUTPUT);
pinMode(D4,OUTPUT);
pinMode(D5,OUTPUT);
pinMode(D6,OUTPUT);
pinMode(D7, INPUT);
pinMode(D8, INPUT);
}
int k;
boolean X = false;
boolean Y = true;
void loop(){
int b = digitalRead(D7);
int c = digitalRead(D8);
if(b == HIGH && c == LOW && Y == false) {
Y = true;
k = random(10);
writeNumber(k); delay(250);
Serial.println("B迴圈1"); //按下B
Serial.print("亂數 = "); Serial.println(k);
}
else if(b == LOW && c == LOW && Y == true) {
writeNumber(k); delay(250);
Serial.println("B迴圈2"); //放開B,等待C按下
Serial.print("亂數 = "); Serial.println(k);
}
else if(b == LOW && c == HIGH && Y == true) {
X = !X; Y = false; Serial.println("C迴圈"); //C按下,執行C
if (k <= 5){
writeNumber(10);
for (int n = 0; n <= 2; n++) {
Serial.println("向左,順");
for (int thisPin = 6 - 1; thisPin >= 0; thisPin--) {
digitalWrite(pins[thisPin], HIGH);
delay(100);
digitalWrite(pins[thisPin], LOW);
} //向左,逆
}
}
else if (k >= 6){
writeNumber(10);
for (int n = 0; n <= 2; n++) {
Serial.println("向右,順");
for (int thisPin = 0; thisPin < 6; thisPin++) {
digitalWrite(pins[thisPin], HIGH);
delay(100);
digitalWrite(pins[thisPin], LOW);
} //向右,順
}
}
}
else if(b == LOW && c == LOW && Y == false){
for(int n = 0; n <= 9; n++){
writeNumber(n); delay(250);
Serial.println("A迴圈"); //C執行結束,進入A,等待B按下
}
}
}
* 有B.C兩顆按鈕,兩顆沒有按下時,
* 0~9循環(A迴圈),
* 按下B時,亂數K,顯示K,直到按下C
* 按下C時,如果K是0~5,向左三圈
* 如果K是6~9,向右三圈
* 然後繼續循換0~9
*/
int pins[7] = {D3,D2,D4,D5,D6,D0,D1};
const boolean data[11][7] = {
1,1,1,1,1,1,0, // 0
0,1,1,0,0,0,0, // 1
1,1,0,1,1,0,1, // 2
1,1,1,1,0,0,1, // 3
0,1,1,0,0,1,1, // 4
1,0,1,1,0,1,1, // 5
1,0,1,1,1,1,1, // 6
1,1,1,0,0,1,0, // 7
1,1,1,1,1,1,1, // 8
1,1,1,1,0,1,1, // 9
0,0,0,0,0,0,0, }; // 10 ( off_all_LED )
void writeNumber(int n){ //把七段顯示器顯示函式獨立
for(int i = 0; i < 7; i++){
digitalWrite(pins[i], data[n][i] == HIGH);
} }
void setup(){
Serial.begin(9600);
pinMode(D0,OUTPUT);
pinMode(D1,OUTPUT);
pinMode(D2,OUTPUT);
pinMode(D3,OUTPUT);
pinMode(D4,OUTPUT);
pinMode(D5,OUTPUT);
pinMode(D6,OUTPUT);
pinMode(D7, INPUT);
pinMode(D8, INPUT);
}
int k;
boolean X = false;
boolean Y = true;
void loop(){
int b = digitalRead(D7);
int c = digitalRead(D8);
if(b == HIGH && c == LOW && Y == false) {
Y = true;
k = random(10);
writeNumber(k); delay(250);
Serial.println("B迴圈1"); //按下B
Serial.print("亂數 = "); Serial.println(k);
}
else if(b == LOW && c == LOW && Y == true) {
writeNumber(k); delay(250);
Serial.println("B迴圈2"); //放開B,等待C按下
Serial.print("亂數 = "); Serial.println(k);
}
else if(b == LOW && c == HIGH && Y == true) {
X = !X; Y = false; Serial.println("C迴圈"); //C按下,執行C
if (k <= 5){
writeNumber(10);
for (int n = 0; n <= 2; n++) {
Serial.println("向左,順");
for (int thisPin = 6 - 1; thisPin >= 0; thisPin--) {
digitalWrite(pins[thisPin], HIGH);
delay(100);
digitalWrite(pins[thisPin], LOW);
} //向左,逆
}
}
else if (k >= 6){
writeNumber(10);
for (int n = 0; n <= 2; n++) {
Serial.println("向右,順");
for (int thisPin = 0; thisPin < 6; thisPin++) {
digitalWrite(pins[thisPin], HIGH);
delay(100);
digitalWrite(pins[thisPin], LOW);
} //向右,順
}
}
}
else if(b == LOW && c == LOW && Y == false){
for(int n = 0; n <= 9; n++){
writeNumber(n); delay(250);
Serial.println("A迴圈"); //C執行結束,進入A,等待B按下
}
}
}
七段顯示器獨立函數
// http://coopermaa2nd.blogspot.tw/2010/12/arduino-lab7.html
//http://yehnan.blogspot.tw/2013/08/arduino_26.html (四合一七段顯示器)
#define NUM 7
int pins[NUM] = {D3,D2,D4,D5,D6,D0,D1};
#define t true
#define f false
boolean data[10][NUM] = {
{1,1,1,1,1,1,0}, // 0
{0,1,1,0,0,0,0}, // 1
{1,1,0,1,1,0,1}, // 2
{1,1,1,1,0,0,1}, // 3
{0,1,1,0,0,1,1}, // 4
{1,0,1,1,0,1,1}, // 5
{1,0,1,1,1,1,1}, // 6
{1,1,1,0,0,1,0}, // 7
{1,1,1,1,1,1,1}, // 8
{1,1,1,1,0,1,1}, // 9
};
// 把七段顯示器的顯示函式獨立出來。
// 輸入數字n(從0到9)
// 根據數字n,就可從data[n]找出七段顯示器的點亮、熄滅資料,
// 然後用迴圈,逐一設定8個腳位的HIGH或LOW,
// 也就等於點亮、熄滅那8個部分
void writeNumber(int n){
for(int i = 0; i < NUM; i++){
digitalWrite(pins[i], data[n][i] == t ? HIGH : LOW);
}
}
void setup(){
for(int i = 0; i < NUM; i++){
pinMode(pins[i], OUTPUT);
}
}
// 寫好writeNumber()後,loop()就簡單了。
// 迴圈從0到9,以七段顯示器顯示該數字,中間延遲1秒。
// 也就是說,會從0數到9,然後再從頭從0開始數。
void loop(){
for(int n = 0; n <= 9; n++){
writeNumber(n);
delay(300);
}
}
//http://yehnan.blogspot.tw/2013/08/arduino_26.html (四合一七段顯示器)
#define NUM 7
int pins[NUM] = {D3,D2,D4,D5,D6,D0,D1};
#define t true
#define f false
boolean data[10][NUM] = {
{1,1,1,1,1,1,0}, // 0
{0,1,1,0,0,0,0}, // 1
{1,1,0,1,1,0,1}, // 2
{1,1,1,1,0,0,1}, // 3
{0,1,1,0,0,1,1}, // 4
{1,0,1,1,0,1,1}, // 5
{1,0,1,1,1,1,1}, // 6
{1,1,1,0,0,1,0}, // 7
{1,1,1,1,1,1,1}, // 8
{1,1,1,1,0,1,1}, // 9
};
// 把七段顯示器的顯示函式獨立出來。
// 輸入數字n(從0到9)
// 根據數字n,就可從data[n]找出七段顯示器的點亮、熄滅資料,
// 然後用迴圈,逐一設定8個腳位的HIGH或LOW,
// 也就等於點亮、熄滅那8個部分
void writeNumber(int n){
for(int i = 0; i < NUM; i++){
digitalWrite(pins[i], data[n][i] == t ? HIGH : LOW);
}
}
void setup(){
for(int i = 0; i < NUM; i++){
pinMode(pins[i], OUTPUT);
}
}
// 寫好writeNumber()後,loop()就簡單了。
// 迴圈從0到9,以七段顯示器顯示該數字,中間延遲1秒。
// 也就是說,會從0數到9,然後再從頭從0開始數。
void loop(){
for(int n = 0; n <= 9; n++){
writeNumber(n);
delay(300);
}
}
A.B - Button
void setup() {
pinMode(D0, OUTPUT);
pinMode(D1, OUTPUT);
pinMode(D2, OUTPUT);
pinMode(D3, OUTPUT);
pinMode(D4, OUTPUT);
pinMode(D5, OUTPUT);
pinMode(D6, OUTPUT);
pinMode(D7,INPUT_PULLUP);
pinMode(D8,INPUT_PULLUP);
}
void loop() {
int a = digitalRead(D7);
int b = digitalRead(D8);
if (a == HIGH) {
digitalWrite(D0,HIGH);
digitalWrite(D1,LOW);
digitalWrite(D2,LOW);
digitalWrite(D3,LOW);
digitalWrite(D4,LOW);
digitalWrite(D5,LOW);
digitalWrite(D6,HIGH);
}
if (b == HIGH) {
digitalWrite(D0,LOW);
digitalWrite(D1,LOW);
digitalWrite(D2,HIGH);
digitalWrite(D3,LOW);
digitalWrite(D4,HIGH);
digitalWrite(D5,LOW);
digitalWrite(D6,LOW);
}
}
pinMode(D0, OUTPUT);
pinMode(D1, OUTPUT);
pinMode(D2, OUTPUT);
pinMode(D3, OUTPUT);
pinMode(D4, OUTPUT);
pinMode(D5, OUTPUT);
pinMode(D6, OUTPUT);
pinMode(D7,INPUT_PULLUP);
pinMode(D8,INPUT_PULLUP);
}
void loop() {
int a = digitalRead(D7);
int b = digitalRead(D8);
if (a == HIGH) {
digitalWrite(D0,HIGH);
digitalWrite(D1,LOW);
digitalWrite(D2,LOW);
digitalWrite(D3,LOW);
digitalWrite(D4,LOW);
digitalWrite(D5,LOW);
digitalWrite(D6,HIGH);
}
if (b == HIGH) {
digitalWrite(D0,LOW);
digitalWrite(D1,LOW);
digitalWrite(D2,HIGH);
digitalWrite(D3,LOW);
digitalWrite(D4,HIGH);
digitalWrite(D5,LOW);
digitalWrite(D6,LOW);
}
}
state machine - Flag - 狀態機
// https://zerojudge.tw/ShowProblem?problemid=d618
// https://milochen.wordpress.com/2011/03/18/programming-thinking-from-flag-to-state-machine-new-method/
// key word - 狀態機 - state machine - Flag
boolean X = false;
boolean Y = true;
void setup() {
Serial.begin(9600);
pinMode(D5,OUTPUT);
pinMode(D7,INPUT);
pinMode(D8,INPUT);
}
void loop() {
int b = digitalRead(D7);
int c = digitalRead(D8);
if (b == HIGH && c == LOW && Y == false ) {
Y = true;
Serial.println("B迴圈1"); //按下B,
}
else if(b == LOW && c == LOW && Y == true ) {
Serial.println("B迴圈2"); //放開B,等待C按下
}
else if(b == LOW && c == HIGH && Y == true ) {
X = !X; Y = false;
Serial.println("C迴圈"); //C按下,執行C
}
else if(b == LOW && c == LOW && Y == false){
Serial.println("A迴圈"); //C執行結束,進入A,等待B按下
}
delay (350);
}
// https://milochen.wordpress.com/2011/03/18/programming-thinking-from-flag-to-state-machine-new-method/
// key word - 狀態機 - state machine - Flag
boolean X = false;
boolean Y = true;
void setup() {
Serial.begin(9600);
pinMode(D5,OUTPUT);
pinMode(D7,INPUT);
pinMode(D8,INPUT);
}
void loop() {
int b = digitalRead(D7);
int c = digitalRead(D8);
if (b == HIGH && c == LOW && Y == false ) {
Y = true;
Serial.println("B迴圈1"); //按下B,
}
else if(b == LOW && c == LOW && Y == true ) {
Serial.println("B迴圈2"); //放開B,等待C按下
}
else if(b == LOW && c == HIGH && Y == true ) {
X = !X; Y = false;
Serial.println("C迴圈"); //C按下,執行C
}
else if(b == LOW && c == LOW && Y == false){
Serial.println("A迴圈"); //C執行結束,進入A,等待B按下
}
delay (350);
}
左右Loading - 七段顯示器
左右Loading
int timer = 100;
int pins[7] = {D3, D2, D4, D5, D6, D0 };
void setup() {
for (int thisPin = 0; thisPin < 6; thisPin++) {
pinMode(pins[thisPin], OUTPUT); }
}
void loop() {
for (int thisPin = 0; thisPin < 6; thisPin++) {
digitalWrite(pins[thisPin], HIGH);
delay(timer);
digitalWrite(pins[thisPin], LOW); }
for (int thisPin = 6 - 1; thisPin >= 0; thisPin--) {
digitalWrite(pins[thisPin], HIGH);
delay(timer);
digitalWrite(pins[thisPin], LOW); }
}
訂閱:
文章 (Atom)
-
https://github.com/spacehuhn/esp8266_deauther/wiki http://arbu00.blogspot.com/2015/11/build-btsmartcar-with-3dp-arduino-hwsw.html
-
http://pizgchen.blogspot.com/2017/04/nodemcu-lab0.html