|
采用二個Arduino uno 一個采集溫度 另一個根據(jù)采集到的值進行處理
111.png (109.22 KB, 下載次數(shù): 72)
下載附件
2020-7-15 23:09 上傳
//引入依賴
#include <LiquidCrystal.h>
#include "Adafruit_Keypad.h"
#include <MsTimer2.h>
// 初始化針腳
const int rs = 13,en = 12,d4 = 11,d5 = 10,d6 = 9,d7 = 8;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
const byte ROWS = 4; // rows
const byte COLS = 4; // columns
unsigned char code_my[]="T:00.0-H:00-L:00";
//define the symbols on the buttons of the keypads
char keys[ROWS][COLS] = {
{'-','1','2','3'},
{'-','4','5','6'},
{'-','7','8','9'},
{'-','*','0','#'}
};
byte rowPins[ROWS] = {7, 6, 5, 4}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {A3,A0, A1, A2}; //connect to the column pinouts of the keypad
//initialize an instance of class NewKeypad
Adafruit_Keypad customKeypad = Adafruit_Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS);
String code_kaisuo= "T:00.0 H:00 L:00";
unsigned char keypad;
unsigned char val[4]={1,2,3,4};
unsigned char mingjiao ;
int addr = 0;
int iii;
boolean TH=false;
boolean TL= false;
unsigned char temp_H[]={0x00,0x00};
unsigned char temp_L[]={0x00,0x00};
unsigned char wendu_temp;
unsigned char wendu_H;
unsigned char wendu_L;
void setup() {
customKeypad.begin();
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
Serial.begin(9600);
lcd.setCursor(0, 0);
lcd.print(code_kaisuo);
MsTimer2::set(100, flash); // 100ms period
MsTimer2::start();
}
void flash()
{
customKeypad.tick();
while(customKeypad.available()){
keypadEvent e = customKeypad.read();
if(e.bit.EVENT == KEY_JUST_RELEASED)
{
keypad=(char)e.bit.KEY;
}
}
if(keypad=='*'){
TH =bool(1-TH) ;
keypad=0;
Serial.println(TH);
}
if(keypad=='#'){
TL=bool(1-TL);
keypad=0;
Serial.println("TL");
}
if(TH==true&&keypad>='0'&&keypad<='9'){
temp_H[0]=temp_H[1];
temp_H[1]=keypad-'0';
keypad=0;
}
if(TL==true&&keypad>='0'&&keypad<='9'){
temp_L[0]=temp_L[1];
temp_L[1]=keypad-'0';
keypad=0;
}
}
void loop() {
lcd.setCursor(9, 0);
lcd.print(temp_H[0]);
lcd.setCursor(10, 0);
lcd.print(temp_H[1]);
lcd.setCursor(14, 0);
lcd.print(temp_L[0]);
lcd.setCursor(15, 0);
lcd.print(temp_L[1]);
lcd.setCursor(2, 0);
lcd.print(val[1]);
lcd.setCursor(3, 0);
lcd.print(val[2]);
lcd.setCursor(5, 0);
lcd.print(val[3]);
wendu_temp=val[1]*10+val[2];
wendu_H=temp_H[0]*10+temp_H[1];
wendu_L=temp_L[0]*10+temp_L[1];
while (Serial.available() > 0)
{
val[iii]= Serial.read();
if(iii==4){
iii=0;
}
else iii++;
}
if(wendu_temp<wendu_L)digitalWrite(2, HIGH);
else if(wendu_temp>wendu_L&&wendu_temp<wendu_H)digitalWrite(2, LOW);
if(wendu_temp>wendu_H)digitalWrite(3, HIGH);
else if(wendu_temp<wendu_H&&wendu_temp>wendu_L) digitalWrite(3, LOW);
}
|
評分
-
查看全部評分
|