|
第一個是人體紅外線程式const int pir = 2;const int led = 13; int p = 0; void setup() { Serial.begin(9600); pinMode(pir, INPUT); pinMode(led, OUTPUT); }void loop(){ p = digitalRead(pir); if (p == HIGH) { digitalWrite(led, HIGH); Serial.println("Detected"); } else { digitalWrite(led, LOW); Serial.println("No One"); } delay(1000);}第2個是HX711 重量感測程式#include "HX711.h"
int Weight = 0;
int Sec_Count = 0;
int Status = 0,Status_Pre = 1;
int Flag_Up = 0,Flag_Down = 0;void setup()
{
pinMode(7, OUTPUT);
Init_Hx711(); //初始化HX711模組連接的IO設置 Serial.begin(9600);
Serial.print("Welcome to use!\n");
Get_Maopi(); //獲取毛皮
delay(3000);
Get_Maopi(); //獲取毛皮
Serial.print("Start!\n");
}void loop()
{
Weight = Get_Weight(); //計算放在感測器上的重物重量
if(Weight <= 5)
{
Status = 0;
}
else
{
Status = 1;
}
if(Status != Status_Pre)
{
if(Status == 1 && Status_Pre == 0)
{
Flag_Up = 1;
}
if(Status == 0 && Status_Pre == 1)
{
Flag_Down = 1;
}
Status_Pre = Status;
}
if(Flag_Up == 1)
{
Flag_Up = 0;
Sec_Count = 0;
}
if(Status == 1 || Flag_Down == 1)
{
Flag_Down = 0;
Serial.print(Weight); //串口顯示重量
Serial.print("g "); //顯示單位
if(Status == 1)
Serial.print(++Sec_Count);
else
Serial.print(Sec_Count);
Serial.print("s\n");
}
if (Weight >=1000) {
digitalWrite(7, HIGH) ;
} else
digitalWrite(7, LOW) ;
delay(1000); //延時1s} 由於要做專題用,可是不知道為何合併起來顯示錯誤,是哪裡不能合併之類的嗎? 拜託各位大大幫忙了 謝謝 |
|