請按照圖案(1)(2)(3)(4)(5)(6)(7)(8)(9)(10)順序安裝,安裝完(1)(2)(3)先測試螢幕與按鈕是否可作動,後續(4)(5)(6)(7)(8)(9)(10)部分依序安裝便可以依序測試各功能是否可用
按鈕長按超過1秒為更換功能
按鈕短按小於0.8秒為更換模式
旋鈕為調整延遲時間或是調整光亮度與音調所使用
很抱歉,這次廠商出貨有點問題,3色LED大家拿到的是3色共陽,但是請大家自行取得 3色LED 共陰,再按照圖片裝上去即可
另外下圖是這次我大量購買的材料費,請大家參考品名跟價錢
功能依序有:
功能0-溫溼度檢測
模式1全顯示:顯示2個DHT11溫溼度檢測器+2個防水溫度檢測器
模式2單一溫度變化:顯示1個DHT11+1個防水溫度計,並於右方進行6組溫度數據紀錄
模式3兩濕度變化:顯示2個DHT11溼度檢測數值,並記錄4組濕度數據
模式4兩溫度變化:顯示2個防水溫度計檢測數值,並記錄4組溫度數據
功能1-RGB混色
模式R:調整紅色亮度
模式G:調整綠色亮度
模式B:調整藍色亮度
旋鈕:調整亮度數值0-255
功能2-聲音產生器
模式1:31-1000Hz
模式2:31-10000Hz
旋鈕:調整音調數值31-(無源蜂鳴器最低31Hz)
功能3-距離測量
模式1:超快速距離測量(時間不準確),並於右方進行6組溫度數據紀錄
模式2:距離測量
旋鈕:調整測量延遲時間
功能4-馬達轉動:5度-180度
功能5-光敏電阻分光光度計,將三色單顆的LED對準光敏電阻,就可以觀查了
模式W:白光
模式R:紅光
模式G:綠光
模式B:藍光
模式R:紅光
模式G:綠光
模式B:藍光
功能6-顯示名稱
以下是本次的arduino程式
/*
* PHYduinoVR320201129
* design by orangeV,taiwan,tainan 台南大成國中 蔡智恆
* need libraries 需要程式庫<Servo.h>,<DHT.h>,<SPI.h>,<Wire.h>,<Adafruit_GFX.h>,<Adafruit_SSD1306.h>,<OneWire.h>,<DallasTemperature.h>
* Acknowledgments: 龍山國中 鄭志鵬、Proman Huang
*/
int
//對應腳位
//0
//1
//2中斷能力腳位,光閘2
//3~PWM中斷能力腳位
motorPin = 4, //4步進馬達
ledRPin = 5, //5~PWM紅LED
ledGPin = 6, //6~PWM綠LED
cR = 0, cG = 0, cB = 0,
ds18b20 = 7, //7溫度計ds18b20
//8光閘1
buzzer = 9, //9,蜂鳴器 (蜂鳴器可以讓出來)
button = 10, //10,按鈕
ledBPin = 11, //11~PWM藍LED
trigPin = 12, //12超聲波測距Trig Pin
echoPin = 13, //13超聲波測距Echo Pin
Photo = A0, //A0光敏電阻
DHTPin = 15, //A1溫濕度DHT
DHT2Pin = 16, //A2溫濕度DHT2
potPin = 17, //A3可變電阻旋鈕
//A4
//A5
//A6
//A7
//常數
R = 0,
menu1N = 5,
menu2N = 7,
delaytime = 0;
float cm = 0.0, cm0[9] = {0}, cm1[9];
int i=0 , j;
//motor
#include <Servo.h>
Servo myservo;
//DHT11/22
#include <DHT.h>
DHT dht(DHTPin, DHT11);
DHT dht2(DHT2Pin, DHT11);
//D18B20
#include <OneWire.h>
#include <DallasTemperature.h>
OneWire oneWire(ds18b20);
DallasTemperature sensors(&oneWire);
//OLED
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET -1
Adafruit_SSD1306 display(OLED_RESET);
//OLEDsetting
#define LOGO16_GLCD_HEIGHT 32
#define LOGO16_GLCD_WIDTH 16
#if (SSD1306_LCDHEIGHT != 32)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
const unsigned char PHYduino_Logo [] PROGMEM = {
0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe,
0x5f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfa,
0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e,
0x67, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe6,
0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa6,
0x66, 0xff, 0xfc, 0xff, 0xfc, 0xe0, 0x38, 0x00, 0x18, 0x00, 0x00, 0x00, 0x03, 0x80, 0x00, 0x66,
0x66, 0x00, 0x14, 0xa0, 0x14, 0xa0, 0x68, 0x00, 0x18, 0x00, 0x00, 0x00, 0x02, 0x80, 0x00, 0x66,
0x66, 0xfc, 0x0c, 0xc0, 0x0c, 0xc0, 0x98, 0x00, 0x18, 0x00, 0x00, 0x00, 0x03, 0x80, 0x00, 0x66,
0x66, 0x0c, 0x0c, 0xc0, 0x00, 0x83, 0x18, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0xa6,
0x66, 0x0c, 0x0c, 0xc0, 0x00, 0x8c, 0x18, 0x00, 0x18, 0x00, 0x00, 0x00, 0x03, 0x80, 0x00, 0xe6,
0x66, 0x0c, 0x1c, 0xe0, 0x00, 0xd0, 0x18, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x02, 0x80, 0x00, 0x06,
0x66, 0xf7, 0xf4, 0xa0, 0x1c, 0xa0, 0x39, 0xff, 0xf7, 0x80, 0x7f, 0xc3, 0xf3, 0x06, 0x00, 0xe6,
0x66, 0xac, 0x18, 0xff, 0xf4, 0xff, 0xe9, 0x40, 0x1e, 0x80, 0x51, 0x42, 0xd3, 0x05, 0xff, 0xa6,
0x66, 0xcc, 0x00, 0x00, 0x0c, 0x00, 0x39, 0x80, 0x19, 0x80, 0xf1, 0xf3, 0x33, 0x06, 0x00, 0x66,
0x66, 0x0c, 0x00, 0x00, 0x04, 0x00, 0x19, 0x80, 0x19, 0x83, 0x31, 0x98, 0x33, 0x06, 0x00, 0x66,
0x66, 0x0c, 0x00, 0x00, 0x04, 0x00, 0x19, 0x80, 0x19, 0x8c, 0x31, 0x8e, 0x33, 0x06, 0x00, 0x66,
0x66, 0x0e, 0x00, 0x00, 0x0c, 0x00, 0x39, 0xc0, 0x39, 0xb0, 0x31, 0x83, 0xb3, 0x92, 0x00, 0x66,
0x66, 0x0a, 0x00, 0x00, 0x14, 0x00, 0x29, 0x40, 0x29, 0x40, 0x51, 0x40, 0xd2, 0xad, 0xff, 0xa6,
0x67, 0x0f, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xf9, 0xff, 0xf9, 0xc0, 0x73, 0xc6, 0x00, 0xe6,
0x65, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x66,
0x67, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf6,
0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e,
0x5f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfa,
0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
//menu
int mode1=1, mode2=0;
void setup() {
Serial.begin(9600);
//buzzer
pinMode(buzzer,OUTPUT);
//soundsonic
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
//ds18b20
sensors.begin();
//button
pinMode(button, INPUT_PULLUP);
//DHT
Wire.begin();
dht.begin();
dht2.begin();
//motor
myservo.attach(motorPin);
//Photoresistor
pinMode(Photo, INPUT);
//OLED
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.display();
display.clearDisplay();
display.drawBitmap(0, 8, PHYduino_Logo, 128, 64, WHITE);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.setTextSize(1);
display.print("orangeV TCJHS.lab V3");
display.display();
delay(1500);
display.clearDisplay();
}
void loop() {
int sw = digitalRead(button);
R = analogRead(potPin);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.setTextSize(1);
if(sw == HIGH)menu();
if(mode2 == 0)DHTxx();
if(mode2 == 1)RGBLED();
if(mode2 == 2)Buzzer();
if ( mode2 != 2 ) noTone(buzzer);
if(mode2 == 3)supersonic();
if(mode2 == 4)motor();
if ( mode2 != 4 ) myservo.write(0);
if(mode2 == 6)openmenu();
if(mode2 == 5)Photoresistor();
if(mode2 != 1 && mode2 != 5 ){
analogWrite(ledRPin, 0);//調弱輸出電壓,保護LED燈跟眼睛
analogWrite(ledGPin, 0);
analogWrite(ledBPin, 0);
}
}
void menu(){
int k0,k1,tt=0;
AA1: k0=digitalRead(button); delay(30);
k1 = digitalRead(button);
if (k1==LOW) goto AA1; //判断按键是否低电平,如果低,循环检测,如果高则下一句
AA2: tt++; //对按键高电平计数
k0 = digitalRead(button); delay(10);
k1 = digitalRead(button);
if (k1==HIGH) goto AA2; //判断按键是否高电平,如果高,继续计数,如果低电平,则表示按键结束
if (tt<80) mode1 = mode1 + 1; //如果按键时间小于80*10ms=0.8s
if (tt>100) mode2 = mode2 + 1; //如果按键时间大于100*10ms=1s
if ( mode2 == menu2N ) mode2 = 0;
if ( mode1 == menu1N ) mode1 = 1;
}
void Buzzer(){
R = analogRead(potPin);
int R1=0,R10=0;
if ( mode1 >= 3 ) mode1 = 1;
display.print("Sound");
display.setCursor(40,0);
if (mode1==1){
display.println(" 31 ~ 1000 HZ");
}else{
display.println(" 31 ~ 10000 HZ");
}
display.setTextSize(2);
if(R<31){
noTone(buzzer);
display.print(0);
}else{
if(mode1==1){
R1 = R - 10;
tone(buzzer,R1);
display.print(R1);
}else if(mode1==2){
R10 = R*10-100;
tone(buzzer,R10);
display.print(R10);
}
}
display.setCursor(60,12);
display.println("Hz");
display.display();
display.clearDisplay();
delay(100);
}
void supersonic(){
digitalWrite(trigPin, LOW);
delayMicroseconds(5);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
float duration = pulseIn (echoPin, HIGH),
cm = (duration) / 58.2
;
if ( mode1 >= 3 ) mode1 = 1;
display.print("SoundSonic 2to60");
display.setCursor(100,0);
display.print("mod");
display.println(mode1);
display.setTextSize(1);
display.print("t= ");
R = analogRead(potPin);
delaytime = R/100 * 100+100;
if(mode1==2) delaytime = delaytime/10;
display.print(delaytime);
if(mode1==1) delaytime = delaytime - 90;
if(mode1==2) delaytime = delaytime - 10;
display.setCursor(44,8);
display.println("ms");
int cm10=cm*10;
display.setTextSize(2);
if (cm<60&&cm>2){
display.print(cm10/10);
display.setTextSize(1);
display.setCursor(25,23);
display.print(".");
int cm100=cm*100;
display.print(cm100%100/10);
}else{
display.print("err");
}
display.setTextSize(2);
display.setCursor(37,16);
display.println("CM");
display.display();
display.clearDisplay();
if(mode1==1||mode1==2){
Serial.print(cm);
Serial.print("CM");
Serial.print(delaytime);
Serial.println("ms");
if(i>=9)i=0;
if(i<9){
if (cm<60&&cm>3){
cm0[i]=cm;
}else{
cm0[i]=0;
}
display.setTextSize(1);
display.setCursor(70+20*(i%3),(i/3)*7+10);
display.print("*");
display.setCursor(75,10);
display.print(cm0[0],0);
display.setCursor(95,10);
display.print(cm0[1],0);
display.setCursor(115,10);
display.print(cm0[2],0);
display.setCursor(75,16);
display.print(cm0[3],0);
display.setCursor(95,16);
display.print(cm0[4],0);
display.setCursor(115,16);
display.print(cm0[5],0);
display.setCursor(75,23);
display.print(cm0[6],0);
display.setCursor(95,23);
display.print(cm0[7],0);
display.setCursor(115,23);
display.print(cm0[8],0);
i++;
}
}
delay(delaytime);
}
void DHTxx() {
sensors.requestTemperatures();
float DHThum = dht.readHumidity();
float DHTtemp = dht.readTemperature();
float cc = sensors.getTempCByIndex(0);
float cc1 = sensors.getTempCByIndex(1);
float DHT2hum = dht2.readHumidity();
float DHT2temp = dht2.readTemperature();
display.print("T & H ");
display.print("t = ");
R = map(R, 0, 1020, 1,10 ); // 0-1024 -> 1-10
delaytime = R*500-400;
display.print(delaytime+900);
display.print(" ms");
if ( mode1 >= 5 ) mode1 = 1;
display.print(" m");
display.println(mode1);
if (mode1 == 2) {
display.print(DHThum, 0); //小數點0位
display.print("% ");
display.print(DHTtemp, 1); //小數點1位
display.println("C");
display.setTextSize(2);
if (cc > -127) {
display.print(cc, 1);
}
display.print("C");
if (i >= 6)i = 0;
if (i < 6) {
if (cc > -170) {
cm0[i] = cc;
} else {
cm0[i] = 0;
}
display.setTextSize(1);
display.setCursor(60 + 30 * (i % 2), (i / 2) * 6 + 10);
display.print("*");
display.setCursor(65, 10);
display.print(cm0[0], 1);
display.setCursor(95, 10);
display.print(cm0[1], 1);
display.setCursor(65, 16);
display.print(cm0[2], 1);
display.setCursor(95, 16);
display.print(cm0[3], 1);
display.setCursor(65, 22);
display.print(cm0[4], 1);
display.setCursor(95, 22);
display.print(cm0[5], 1);
i++;
}
}
if (mode1 == 1) {
display.print("DHT1= ");
display.print(DHThum, 0); //小數點0位
display.print("% ");
display.print(DHTtemp, 1); //小數點1位
display.println("C");
display.print("DHT2= ");
display.print(DHT2hum, 0); //小數點0位
display.print("% ");
display.print(DHT2temp, 1); //小數點1位
display.println("C");
display.print("T1= ");
if (cc > -127) {
display.print(cc, 1);
}
display.print("C ");
display.print("T2= ");
if (cc1 > -127) {
display.print(cc1, 1);
}
display.println("C");
}
if (mode1 == 3) {
if (i < 5) {
if (DHThum >= 0) {
cm0[i] = DHThum;
} else {
cm0[i] = 0;
}
if (i < 5) {
if (DHT2hum >= 0) {
cm1[i] = DHT2hum;
} else {
cm1[i] = 0;
}
if (i >= 4)i = 0;
display.setTextSize(1);
display.setCursor(5, 10);
display.print(" H1 H2");
display.setCursor(65, 10);
display.print(" H1 H2");
display.setCursor(60* (i % 2), (i / 2) * 4 + 18);
display.print("*");
display.setCursor(8, 16);
display.print(cm0[1], 0);
display.print("% ");
display.print(cm1[1], 0);
display.print("%");
display.setCursor(68, 16);
display.print(cm0[2], 0);
display.print("% ");
display.print(cm1[2], 0);
display.print("%");
display.setCursor(8, 22);
display.print(cm0[3], 0);
display.print("% ");
display.print(cm1[3], 0);
display.print("%");
display.setCursor(68, 22);
display.print(cm0[4], 0);
display.print("% ");
display.print(cm1[4], 0);
display.print("%");
}
}
i++;
}
if (mode1 == 4) {
if (i < 5) {
if (cc > -170) {
cm0[i] = cc;
} else {
cm0[i] = 0;
}
if (i < 5) {
if (cc1 > -170) {
cm1[i] = cc1;
} else {
cm1[i] = 0;
}
if (i >= 4)i = 0;
display.setTextSize(1);
display.setCursor(5, 10);
display.print(" T1 T2");
display.setCursor(65, 10);
display.print(" T1 T2");
display.setCursor(60* (i % 2), (i / 2) * 4 + 18);
display.print("*");
display.setCursor(8, 16);
display.print(cm0[1], 0);
display.print("c ");
display.print(cm1[1], 0);
display.print("c");
display.setCursor(68, 16);
display.print(cm0[2], 0);
display.print("c ");
display.print(cm1[2], 0);
display.print("c");
display.setCursor(8, 22);
display.print(cm0[3], 0);
display.print("c ");
display.print(cm1[3], 0);
display.print("c");
display.setCursor(68, 22);
display.print(cm0[4], 0);
display.print("c ");
display.print(cm1[4], 0);
display.print("c");
}
}
i++;
}
display.display();
display.clearDisplay();
delay(delaytime);
delaytime = 0;
}
void motor(){
R = 0;
R = analogRead(potPin);
R = map(R, 0, 1023, 0, 175); // 0-1024 -> 0-180
myservo.write(R);
display.println("motor 5 ~ 180");
display.setTextSize(2);
display.print("angle ");
display.print(R+5);
delay(15);
display.display();
display.clearDisplay();
}
void RGBLED(){
R = 0;
if ( mode1 >= 4 ) mode1 = 1;
R = analogRead(potPin);
R = map(R, 0, 1020, 0, 255); // 0-1024 -> 0-255
display.print("RGB LED");
if(mode1==1){
display.println(" R");
cR=R;
}else if(mode1==2){
display.println(" G");
cG=R;
}else if(mode1==3){
display.println(" B");
cB=R;
}else{
display.println(" clear");
cR=0;
cG=0;
cB=0;
}
display.print("R=");
display.println(cR);
display.print("G=");
display.println(cG);
display.print("B=");
display.println(cB);
display.display();
display.clearDisplay();
analogWrite(ledRPin, cR*0.8);//調弱輸出電壓,保護LED燈跟眼睛
analogWrite(ledGPin, cG*0.8);
analogWrite(ledBPin, cB*0.8);
}
void openmenu(){
display.setTextSize(1);
display.print("orangeV TCJHS.lab V3");
display.drawBitmap(0, 8, PHYduino_Logo, 128, 64, WHITE);
display.display();
display.clearDisplay();
R = 0;
mode1 = 1;
}
void Photoresistor(){
int pr = analogRead(Photo);
int cR = 0, cG = 0, cB = 0;
if ( mode1 >= 5 ) mode1 = 1;
display.print("Photo");
if(mode1==1){
display.println(" W");
cR=200;
cG=200;
cB=200;
}else if(mode1==2){
display.println(" R");
cR=200;
}else if(mode1==3){
display.println(" G");
cG=200;
}else if(mode1==4){
display.println(" B");
cB=200;
}else{
display.println(" clear");
cR=0;
cG=0;
cB=0;
}
Serial.println(pr);
display.setTextSize(2);
display.print("Light ");
display.print(pr);
delay(15);
display.display();
display.clearDisplay();
analogWrite(ledRPin, cR);//調弱輸出電壓,保護LED燈跟眼睛
analogWrite(ledGPin, cG);
analogWrite(ledBPin, cB);
}
沒有留言:
張貼留言