找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2736|回复: 3
收起左侧

Arduino温控系统程序+电路

[复制链接]
ID:770888 发表于 2020-7-15 23:09 | 显示全部楼层 |阅读模式
采用二个Arduino uno 一个采集温度 另一个根据采集到的值进行处理
111.png

//引入依赖
#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);
}

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

回复

使用道具 举报

ID:102963 发表于 2020-7-16 12:29 | 显示全部楼层
怎么感觉楼主的程序不全呢?
回复

使用道具 举报

ID:118954 发表于 2020-7-17 16:41 | 显示全部楼层
今天我算是深刻认识到如果没写注释,再简单的程序也看得费劲
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表