首页 > 分享 > STM32项目分享:宠物喂食(蓝牙升级版)

STM32项目分享:宠物喂食(蓝牙升级版)

目录

 一、前言

 二、项目简介

1.功能详解

2.主要器件

三、原理图设计

四、PCB硬件设计

PCB图 

五、程序设计 

六、实验效果 ​编辑

 七、包含内容

  项目分享

一、前言

项目成品图片:

哔哩哔哩视频链接:

【STM32宠物喂食(蓝牙升级版)】 https://www.bilibili.com/video/BV1vUDfBnEQf/?share_source=copy_web&vd_source=097fdeaf6b6ecfed8a9ff7119c32faf2

(资料分享见文末) 

 二、项目简介

1.功能详解

基于STM32的智能家居语音系统

功能如下:

温湿度采集:DHT11检测宠物窝的温湿度。宠物靠近检测:光电红外传感器检测是否有宠物靠近。重量检测:HX711称重模块检测投喂食物的重量水位检测:通过水位传感器检测喂水水位屏幕显示:OLED屏实时显示当前时间、宠物窝的温度、湿度,食物重量和水位。投喂控制:步进电机模拟进行喂食控制自动模式:达到定时时间后开启自动喂食同时扬声器播报语音并伴随蜂鸣器提醒,喂食后重量达到设定值再返回结束喂食;当宠物靠近且水位低于阈值时候自动喂水手动模式:手动模式下通过按键可控制喂食和喂水的开关功能模式切换:按键可切换自动模式和手动模式阈值调节:按键可设置当前时间、3个定时喂食的时间、食物重量阈值和水位阈值手机APP:通过蓝牙连接手机APP可接收当前环境信息数据,可切换模式和完成控制指令下发 2.主要器件 STM32F103C8T6单片机DHT11温湿度传感器OLED 屏幕HX711称重模块光电红外传感器BT04A(蓝牙)LED灯步进电机ULN2003步进电机驱动芯片JR6001语音模块水位传感器有源蜂鸣器扬声器继电器水泵

三、原理图设计

四、PCB硬件设计

PCB图  

五、程序设计 

#include "stm32f10x.h"

#include "led.h"

#include "beep.h"

#include "usart.h"

#include "usart2.h"

#include "usart3.h"

#include "delay.h"

#include "dht11.h"

#include "oled.h"

#include "key.h"

#include "Modules.h"

#include "TIM2.h"

#include "adcx.h"

#include "flash.h"

#include "stepmotor.h"

#include "bump.h"

#include "HW.h"

#include "hx711.h"

#include "water.h"

#include "relay.h"

#include "rtc.h"

#define KEY_Long111

#define KEY_11

#define KEY_22

#define KEY_33

#define KEY_44

#define FLASH_START_ADDR0x0801f000

uint8_t dakai = 0;

uint8_t Flag_dakai = 0;

extern uint8_t rtc_get_flag;

SensorModules sensorData;

SensorThresholdValue Sensorthreshold;

DriveModules driveData;

uint8_t mode = 1;

int32_t reset;

uint8_t location = 1;

static uint8_t count_w = 1;

uint8_t set_flag = 1;

uint8_t ss_flag = 1;

uint8_t count = 0;

uint8_t date;

float Pi_weight;

uint8_t food_flag_1 = 0;

uint8_t food_flag_2 = 0;

uint8_t food_flag_3 = 0;

uint8_t bobao_flag = 1;

uint32_t time_num = 1;

_calendar_obj set_time;

static uint8_t count_a = 1;

static uint8_t count_m = 1;

static uint8_t count_s = 1;

void Flag_Writer(void);

enum

{

AUTO_MODE = 1,

MANUAL_MODE,

SETTINGS_MODE

}MODE_PAGES;

void OLED_autoPage1(void)

{

OLED_ShowChinese(0,16,13,16,1);

OLED_ShowChinese(16,16,14,16,1);

OLED_ShowChinese(32,16,0,16,1);

OLED_ShowChinese(48,16,2,16,1);

OLED_ShowChar(64,16,':',16,1);

OLED_ShowChinese(0,32,13,16,1);

OLED_ShowChinese(16,32,14,16,1);

OLED_ShowChinese(32,32,1,16,1);

OLED_ShowChinese(48,32,2,16,1);

OLED_ShowChar(64,32,':',16,1);

OLED_ShowChinese(0,48,24,16,1);

OLED_ShowChinese(16,48,25,16,1);

OLED_ShowChar(64,48,':',16,1);

OLED_Refresh();

}

void OLED_autoPage2(void)

{

OLED_ShowChinese(0,0,38,16,1);

OLED_ShowChinese(16,0,44,16,1);

OLED_ShowChar(64,0,':',16,1);

OLED_Refresh();

}

void SensorDataDisplay1(void)

{

char display_buf[48];

sprintf(display_buf,"%02d:%02d:%02d",sensorData.calendarData.hour,sensorData.calendarData.min,sensorData.calendarData.sec);

OLED_ShowString(32,0,(uint8_t*)display_buf,16,1);

OLED_ShowNum(90,16,sensorData.temp,2,16,1);

OLED_ShowNum(90,32,sensorData.humi,2,16,1);

OLED_ShowNum(90,48,sensorData.weight,4,16,1);

OLED_Refresh();

char all_data[128];

const char* person_status = sensorData.HW ? "是" : "否";

sprintf(all_data, " 温度: %drn 湿度: %d rn 质量: %.0frn 水位:%d rn 宠物靠近: %srn",

sensorData.temp,

sensorData.humi,

sensorData.weight,

sensorData.water,

person_status

);

USART2_SendString(all_data);

printf("温度:%drn",sensorData.temp);

printf("湿度:%drn",sensorData.humi);

printf("重量:%.0frn",sensorData.weight);

printf("是否有宠物:%srn",sensorData.HW ? "是" : "否");

}

void SensorDataDisplay2(void)

{

OLED_ShowNum(90,0,sensorData.water,4,16,1);

OLED_Refresh();

char all_data[128];

const char* person_status = sensorData.HW ? "是" : "否";

sprintf(all_data, " 温度: %drn 湿度: %d rn 质量: %.0frn 水位:%d rn 宠物靠近: %srn",

sensorData.temp,

sensorData.humi,

sensorData.weight,

sensorData.water,

person_status

);

USART2_SendString(all_data);

}

void OLED_manualPage1(void)

{

OLED_ShowChinese(16,16,45,16,1);

OLED_ShowChinese(32,16,46,16,1);

OLED_ShowChar(64,16,':',16,1);

OLED_ShowChinese(16,0,38,16,1);

OLED_ShowChinese(32,0,39,16,1);

OLED_ShowChar(64,0,':',16,1);

OLED_Refresh();

}

void OLED_manualPage2(void)

{

}

void ManualSettingsDisplay1(void)

{

if(driveData.Water_Flag)

{

OLED_ShowChinese(96,0,40,16,1);

}

else

{

OLED_ShowChinese(96,0,42,16,1);

}

if(driveData.Food_Flag)

{

OLED_ShowChinese(96,16,40,16,1);

}

else

{

OLED_ShowChinese(96,16,42,16,1);

}

OLED_Refresh();

}

void ManualSettingsDisplay2(void)

{

}

void OLED_settingsPage1(void)

{

OLED_ShowChinese(16,0,49,16,1);

OLED_ShowChinese(32,0,47,16,1);

OLED_ShowChar(48,0,':',16,1);

OLED_ShowChinese(16,16,48,16,1);

OLED_ShowChinese(32,16,49,16,1);

OLED_ShowChar(48, 16, '1', 16, 1);

OLED_ShowChar(64,16,':',16,1);

OLED_ShowChinese(16,32,48,16,1);

OLED_ShowChinese(32,32,49,16,1);

OLED_ShowChar(48, 32, '2', 16, 1);

OLED_ShowChar(64,32,':',16,1);

OLED_ShowChinese(16,48,48,16,1);

OLED_ShowChinese(32,48,49,16,1);

OLED_ShowChar(48, 48, '3', 16, 1);

OLED_ShowChar(64,48,':',16,1);

OLED_Refresh();

}

void OLED_settingsPage2(void)

{

OLED_ShowChinese(16,0,46,16,1);

OLED_ShowChinese(32,0,50,16,1);

OLED_ShowChinese(48,0,26,16,1);

OLED_ShowChinese(64,0,27,16,1);

OLED_ShowChar(80,0,':',16,1);

OLED_ShowChinese(16,16,38,16,1);

OLED_ShowChinese(32,16,44,16,1);

OLED_ShowChinese(48,16,26,16,1);

OLED_ShowChinese(64,16,27,16,1);

OLED_ShowChar(80,16,':',16,1);

OLED_Refresh();

}

void SettingsThresholdDisplay1(void)

{

uint8_t display_buf[48];

sprintf((char*)display_buf,"%02d:%02d:%02d",set_time.hour,set_time.min,set_time.sec);

OLED_ShowString(64, 0, display_buf, 16, 1);

sprintf((char*)display_buf,"%02d:%02d",Sensorthreshold.time_Value_1.hour, Sensorthreshold.time_Value_1.min);

OLED_ShowString(88, 16, display_buf, 16, 1);

sprintf((char*)display_buf,"%02d:%02d",Sensorthreshold.time_Value_2.hour, Sensorthreshold.time_Value_2.min);

OLED_ShowString(88, 32, display_buf, 16, 1);

sprintf((char*)display_buf,"%02d:%02d",Sensorthreshold.time_Value_3.hour, Sensorthreshold.time_Value_3.min);

OLED_ShowString(88, 48, display_buf, 16, 1);

OLED_Refresh();

}

void SettingsThresholdDisplay2(void)

{

OLED_ShowNum(88, 0, Sensorthreshold.weight_Value, 4, 16, 1);

OLED_ShowNum(88, 16, Sensorthreshold.water_Value, 4, 16, 1);

OLED_Refresh();

}

uint8_t SetAuto(void)

{

if(KeyNum == KEY_2)

{

KeyNum = 0;

count_a++;

if (count_a > 2)

{

count_a = 1;

}

OLED_Clear();

}

return count_a;

}

uint8_t SetManual(void)

{

if(KeyNum == KEY_2)

{

KeyNum = 0;

count_m++;

if (count_m > 2)

{

OLED_Clear();

count_m = 1;

}

}

return count_m;

}

uint8_t SetSelection(void)

{

if(KeyNum == KEY_2)

{

KeyNum = 0;

count_s++;

if (count_s == 5)

{

OLED_Clear();

}

else if (count_s > 6)

{

OLED_Clear();

count_s = 1;

}

}

return count_s;

}

void OLED_manualOption(uint8_t num)

{

switch(num)

{

case 1:

OLED_ShowChar(0, 0,'>',16,1);

OLED_ShowChar(0,16,' ',16,1);

OLED_ShowChar(0,32,' ',16,1);

OLED_ShowChar(0,48,' ',16,1);

break;

case 2:

OLED_ShowChar(0, 0,' ',16,1);

OLED_ShowChar(0,16,'>',16,1);

OLED_ShowChar(0,32,' ',16,1);

OLED_ShowChar(0,48,' ',16,1);

break;

default: break;

}

}

void OLED_settingsOption(uint8_t num)

{

switch(num)

{

case 1:

OLED_ShowChar(0, 0,'>',16,1);

OLED_ShowChar(0,16,' ',16,1);

OLED_ShowChar(0,32,' ',16,1);

OLED_ShowChar(0,48,' ',16,1);

break;

case 2:

OLED_ShowChar(0, 0,' ',16,1);

OLED_ShowChar(0,16,'>',16,1);

OLED_ShowChar(0,32,' ',16,1);

OLED_ShowChar(0,48,' ',16,1);

break;

case 3:

OLED_ShowChar(0, 0,' ',16,1);

OLED_ShowChar(0,16,' ',16,1);

OLED_ShowChar(0,32,'>',16,1);

OLED_ShowChar(0,48,' ',16,1);

break;

case 4:

OLED_ShowChar(0, 0,' ',16,1);

OLED_ShowChar(0,16,' ',16,1);

OLED_ShowChar(0,32,' ',16,1);

OLED_ShowChar(0,48,'>',16,1);

break;

case 5:

OLED_ShowChar(0, 0,'>',16,1);

OLED_ShowChar(0,16,' ',16,1);

OLED_ShowChar(0,32,' ',16,1);

OLED_ShowChar(0,48,' ',16,1);

break;

case 6:

OLED_ShowChar(0, 0,' ',16,1);

OLED_ShowChar(0,16,'>',16,1);

OLED_ShowChar(0,32,' ',16,1);

OLED_ShowChar(0,48,' ',16,1);

default: break;

}

}

void AutoControl(void)

{

if ((sensorData.calendarData.hour == Sensorthreshold.time_Value_1.hour && sensorData.calendarData.min == Sensorthreshold.time_Value_1.min)

&& (food_flag_1 == 0))

{

driveData.Food_Flag = 1;

food_flag_1 = 1;

driveData.Beep_Flag = 1;

}

if ((sensorData.calendarData.hour == Sensorthreshold.time_Value_2.hour && sensorData.calendarData.min == Sensorthreshold.time_Value_2.min)

&& (food_flag_2 == 0))

{

driveData.Food_Flag = 1;

food_flag_2 = 1;

driveData.Beep_Flag = 1;

}

if ((sensorData.calendarData.hour == Sensorthreshold.time_Value_3.hour && sensorData.calendarData.min == Sensorthreshold.time_Value_3.min)

&& (food_flag_3 == 0))

{

driveData.Food_Flag = 1;

food_flag_3 = 1;

driveData.Beep_Flag = 1;

}

if (abs((int)sensorData.weight) >= Sensorthreshold.weight_Value)

{

driveData.Food_Flag = 0;

}

if (date != sensorData.calendarData.w_date)

{

date = sensorData.calendarData.w_date;

food_flag_1 = 0;

food_flag_2 = 0;

food_flag_3 = 0;

}

if ((sensorData.water < Sensorthreshold.water_Value) && (sensorData.HW == 1))

{

driveData.Water_Flag = 1;

}

else

{

driveData.Water_Flag = 0;

}

}

void ManualControl(uint8_t num)

{

switch(num)

{

case 1:

if (KeyNum == KEY_3)

{

driveData.Water_Flag = 1;

KeyNum = 0;

}

if (KeyNum == KEY_4)

{

driveData.Water_Flag = 0;

KeyNum = 0;

}

break;

case 2:

if (KeyNum == KEY_3)

{

driveData.Food_Flag = 1;

KeyNum = 0;

}

if (KeyNum == KEY_4)

{

driveData.Food_Flag = 0;

KeyNum = 0;

}

break;

default: break;

}

}

void Control_Manager(void)

{

if (driveData.Beep_Flag)

{

if (count < 3)

{

if (ss_flag)

{

ss_flag = 0;

BEEP_On();

}

else

{

ss_flag = 1;

BEEP_Off();

}

count++;

}

else

{

count = 0;

driveData.Beep_Flag = 0;

}

}

else

{

BEEP_Off();

}

if (driveData.Food_Flag)

{

if (driveData.Now_Food_Flag == 0)

{

if (bobao_flag)

{

USART3_SendString("A7:00002");

bobao_flag = 0;

}

driveData.Now_Food_Flag = 1;

MOTOR_Direction_Angle(0,0,180,1);

}

}

else

{

bobao_flag = 1;

if (driveData.Now_Food_Flag == 1)

{

driveData.Now_Food_Flag = 0;

MOTOR_Direction_Angle(1,0,180,1);

}

}

if (driveData.Water_Flag)

{

RELAY_ON;

}

else

{

RELAY_OFF;

}

}

void OLED_Show_SettingTime()

{

if (location == 1)

{

OLED_ShowString(64, 0, (uint8_t*)" ", 16, 1);

}

else if (location == 2)

{

OLED_ShowString(88, 0, (uint8_t*)" ", 16, 1);

}

else if (location == 3)

{

OLED_ShowString(112, 0, (uint8_t*)" ", 16, 1);

}

else if (location == 4)

{

OLED_ShowString(88, 16, (uint8_t*)" ", 16, 1);

}

else if (location == 5)

{

OLED_ShowString(112, 16, (uint8_t*)" ", 16, 1);

}

else if (location == 6)

{

OLED_ShowString(88, 32, (uint8_t*)" ", 16, 1);

}

else if (location == 7)

{

OLED_ShowString(112, 32, (uint8_t*)" ", 16, 1);

}

else if (location == 8)

{

OLED_ShowString(88, 48, (uint8_t*)" ", 16, 1);

}

else if (location == 9)

{

OLED_ShowString(112, 48, (uint8_t*)" ", 16, 1);

}

}

void ThresholdSettings(uint8_t num)

{

if (num <= 4)

{

OLED_settingsPage1();

SettingsThresholdDisplay1();

}

else

{

OLED_settingsPage2();

SettingsThresholdDisplay2();

}

OLED_settingsOption(num);

switch (num)

{

case 1:

OLED_settingsPage1();

while (1)

{

OLED_Show_SettingTime();

if (KeyNum == KEY_3 )

{

KeyNum = 0;

if (location == 1)

{

set_time.hour += 1;

if (set_time.hour > 23)

{

set_time.hour = 0;

}

}

if (location == 2)

{

set_time.min += 1;

if (set_time.min > 59)

{

set_time.min = 0;

}

}

if (location == 3)

{

set_time.sec += 1;

if (set_time.sec > 59)

{

set_time.sec = 0;

}

}

}

if (KeyNum == KEY_4 )

{

KeyNum = 0;

if (location == 1)

{

set_time.hour -= 1;

if (set_time.hour > 23)

{

set_time.hour = 23;

}

}

if (location == 2)

{

set_time.min -= 1;

if (set_time.min > 59)

{

set_time.min = 59;

}

}

if (location == 3)

{

set_time.sec -= 1;

if (set_time.sec > 59)

{

set_time.sec = 59;

}

}

}

if (KeyNum == KEY_2 )

{

KeyNum = 0;

location++;

if (location > 3)

{

++count_w;

break;

}

}

if (KeyNum == KEY_1)

{

count_a = 1;

Flag_Writer();

break;

}

SettingsThresholdDisplay1();

}

break;

case 2:

while (1)

{

OLED_Show_SettingTime();

if (KeyNum == KEY_3 )

{

KeyNum = 0;

if (location == 4)

{

Sensorthreshold.time_Value_1.hour += 1;

food_flag_1 = 0;

if (Sensorthreshold.time_Value_1.hour > 23)

{

Sensorthreshold.time_Value_1.hour = 0;

}

}

if (location == 5)

{

Sensorthreshold.time_Value_1.min += 1;

food_flag_1 = 0;

if (Sensorthreshold.time_Value_1.min > 59)

{

Sensorthreshold.time_Value_1.min = 0;

}

}

}

else if (KeyNum == KEY_4 )

{

KeyNum = 0;

if (location == 4)

{

Sensorthreshold.time_Value_1.hour -= 1;

food_flag_1 = 0;

if (Sensorthreshold.time_Value_1.hour > 23)

{

Sensorthreshold.time_Value_1.hour = 23;

}

}

if (location == 5)

{

Sensorthreshold.time_Value_1.min -= 1;

food_flag_1 = 0;

if (Sensorthreshold.time_Value_1.min > 59)

{

Sensorthreshold.time_Value_1.min = 59;

}

}

}

else if (KeyNum == KEY_2)

{

KeyNum = 0;

location++;

if (location > 5)

{

++count_w;

break;

}

}

if (KeyNum == KEY_1)

{

count_a = 1;

set_flag = 1;

Flag_Writer();

break;

}

SettingsThresholdDisplay1();

}

break;

case 3:

while (1)

{

OLED_Show_SettingTime();

if (KeyNum == KEY_3 )

{

KeyNum = 0;

if (location == 6)

{

Sensorthreshold.time_Value_2.hour += 1;

food_flag_2 = 0;

if (Sensorthreshold.time_Value_2.hour > 23)

{

Sensorthreshold.time_Value_2.hour = 0;

}

}

if (location == 7)

{

Sensorthreshold.time_Value_2.min += 1;

food_flag_2 = 0;

if (Sensorthreshold.time_Value_2.min > 59)

{

Sensorthreshold.time_Value_2.min = 0;

}

}

}

else if (KeyNum == KEY_4 )

{

KeyNum = 0;

if (location == 6)

{

Sensorthreshold.time_Value_2.hour -= 1;

food_flag_2 = 0;

if (Sensorthreshold.time_Value_2.hour > 23)

{

Sensorthreshold.time_Value_2.hour = 23;

}

}

if (location == 7)

{

Sensorthreshold.time_Value_2.min -= 1;

food_flag_2 = 0;

if (Sensorthreshold.time_Value_2.min > 59)

{

Sensorthreshold.time_Value_2.min = 59;

}

}

}

else if (KeyNum == KEY_2 )

{

KeyNum = 0;

location++;

if (location > 7)

{

++count_w;

break;

}

}

if (KeyNum == KEY_1)

{

count_a = 1;

set_flag = 1;

Flag_Writer();

break;

}

SettingsThresholdDisplay1();

}

break;

case 4:

while (1)

{

OLED_Show_SettingTime();

if (KeyNum == KEY_3)

{

KeyNum = 0;

if (location == 8)

{

Sensorthreshold.time_Value_3.hour += 1;

food_flag_3 = 0;

if (Sensorthreshold.time_Value_3.hour > 23)

{

Sensorthreshold.time_Value_3.hour = 0;

}

}

if (location == 9)

{

Sensorthreshold.time_Value_3.min += 1;

food_flag_3 = 0;

if (Sensorthreshold.time_Value_3.min > 59)

{

Sensorthreshold.time_Value_3.min = 0;

}

}

}

else if (KeyNum == KEY_4 )

{

KeyNum = 0;

if (location == 8)

{

Sensorthreshold.time_Value_3.hour -= 1;

food_flag_3 = 0;

if (Sensorthreshold.time_Value_3.hour > 23)

{

Sensorthreshold.time_Value_3.hour = 23;

}

}

if (location == 9)

{

Sensorthreshold.time_Value_3.min -= 1;

food_flag_3 = 0;

if (Sensorthreshold.time_Value_3.min > 59)

{

Sensorthreshold.time_Value_3.min = 59;

}

}

}

else if (KeyNum == KEY_2 )

{

KeyNum = 0;

location++;

if (location > 9)

{

++count_w;

location = 1;

OLED_Clear();

break;

}

}

if (KeyNum == KEY_1)

{

count_a = 1;

set_flag = 1;

break;

}

SettingsThresholdDisplay1();

}

case 5:

if (KeyNum == KEY_3 )

{

KeyNum = 0;

Sensorthreshold.weight_Value += 10;

if (Sensorthreshold.weight_Value >= 9000)

{

Sensorthreshold.weight_Value = 0;

}

}

else if (KeyNum == KEY_4 )

{

KeyNum = 0;

Sensorthreshold.weight_Value -= 10;

if (Sensorthreshold.weight_Value >= 9000)

{

Sensorthreshold.weight_Value = 9000;

}

}

else if (KeyNum == KEY_2 )

{

KeyNum = 0;

++count_w;

}

case 6:

if (KeyNum == KEY_3 )

{

KeyNum = 0;

Sensorthreshold.water_Value += 1;

if (Sensorthreshold.water_Value >= 100)

{

Sensorthreshold.water_Value = 0;

}

}

else if (KeyNum == KEY_4 )

{

KeyNum = 0;

Sensorthreshold.water_Value -= 1;

if (Sensorthreshold.water_Value >= 100)

{

Sensorthreshold.water_Value = 100;

}

}

else if (KeyNum == KEY_2 )

{

KeyNum = 0;

count_w = 1;

location = 1;

OLED_Clear();

}

default: break;

}

}

void Flag_Writer(void)

{

FLASH_W(FLASH_START_ADDR, Sensorthreshold.time_Value_1.hour, Sensorthreshold.time_Value_1.min,

Sensorthreshold.time_Value_2.hour, Sensorthreshold.time_Value_2.min,

Sensorthreshold.time_Value_3.hour, Sensorthreshold.time_Value_3.min,

Sensorthreshold.weight_Value, Sensorthreshold.water_Value);

RTC_Set(sensorData.calendarData.w_year, sensorData.calendarData.w_month, sensorData.calendarData.w_date, set_time.hour, set_time.min, set_time.sec);

sensorData.calendarData.hour = set_time.hour;

sensorData.calendarData.min = set_time.min;

sensorData.calendarData.sec = set_time.sec;

rtc_get_flag = 1;

}

void Flash_Time_Init(void)

{

Sensorthreshold.time_Value_1.hour = FLASH_R(FLASH_START_ADDR);

Sensorthreshold.time_Value_1.min = FLASH_R(FLASH_START_ADDR + 2);

Sensorthreshold.time_Value_2.hour = FLASH_R(FLASH_START_ADDR + 4);

Sensorthreshold.time_Value_2.min = FLASH_R(FLASH_START_ADDR + 6);

Sensorthreshold.time_Value_3.hour = FLASH_R(FLASH_START_ADDR + 8);

Sensorthreshold.time_Value_3.min = FLASH_R(FLASH_START_ADDR + 10);

Sensorthreshold.weight_Value = FLASH_R(FLASH_START_ADDR + 12);

Sensorthreshold.water_Value = FLASH_R(FLASH_START_ADDR + 14);

if (Sensorthreshold.time_Value_1.hour > 24 || Sensorthreshold.time_Value_1.min > 60

|| Sensorthreshold.time_Value_2.hour > 24 || Sensorthreshold.time_Value_2.min > 60

|| Sensorthreshold.time_Value_3.hour > 24 || Sensorthreshold.time_Value_3.min > 60)

{

FLASH_W(FLASH_START_ADDR, 12, 01, 12, 02, 12, 03, 800, 80);

}

Sensorthreshold.time_Value_1.hour = FLASH_R(FLASH_START_ADDR);

Sensorthreshold.time_Value_1.min = FLASH_R(FLASH_START_ADDR + 2);

Sensorthreshold.time_Value_2.hour = FLASH_R(FLASH_START_ADDR + 4);

Sensorthreshold.time_Value_2.min = FLASH_R(FLASH_START_ADDR + 6);

Sensorthreshold.time_Value_3.hour = FLASH_R(FLASH_START_ADDR + 8);

Sensorthreshold.time_Value_3.min = FLASH_R(FLASH_START_ADDR + 10);

Sensorthreshold.weight_Value = FLASH_R(FLASH_START_ADDR + 12);

Sensorthreshold.water_Value = FLASH_R(FLASH_START_ADDR + 14);

}

void USART2_ProcessCmd(void)

{

if (USART2_GetReceivedFlag())

{

uint8_t* rx_buf = USART2_GetRxBuffer();

switch(rx_buf[0])

{

case 'A':

if (mode == AUTO_MODE)

{

mode = MANUAL_MODE;

OLED_Clear();

count_m = 1;

driveData.Water_Flag = 0;

driveData.Food_Flag = 0;

}

else if (mode == MANUAL_MODE)

{

mode = AUTO_MODE;

OLED_Clear();

}

break;

case 'B':

if (mode == MANUAL_MODE)

{

driveData.Water_Flag = ! driveData.Water_Flag;

count_m = 1;

}

break;

case 'C':

if (mode == MANUAL_MODE)

{

driveData.Food_Flag = !driveData.Food_Flag;

count_m = 2;

}

break;

default:

break;

}

USART2_ClearReceivedFlag();

}

}

int main(void)

{

SystemInit();

delay_init(72);

ADCX_Init();

LED_Init();

LED_On();

Key_Init();

MOTOR_Init();

BUMP_Init();

OLED_Init();

DHT11_Init();

HW_Init();

RTC_Init();

BEEP_Init();

HX711_Init();

WATER_Init();

RELAY_Init();

OLED_Clear();

Pi_weight = Get_Tare();

TIM2_Init(9,14398);

USART1_Config();

USART2_Init();

USART3_Config();

printf("Start n");

USART3_SendString("AF:30");

delay_ms(300);

USART3_SendString("A7:00001");

delay_ms(1000);

OLED_Clear();

Flash_Time_Init();

reset = HX711_GetData();

date = sensorData.calendarData.w_date;

while (1)

{

USART2_ProcessCmd();

SensorScan();

switch(mode)

{

case AUTO_MODE:

if(SetAuto() ==1 )

{

OLED_autoPage1();

SensorDataDisplay1();

}

else

{

OLED_autoPage2();

SensorDataDisplay2();

}

AutoControl();

if (KeyNum == KEY_1)

{

KeyNum = 0;

mode = MANUAL_MODE;

count_m = 1;

OLED_Clear();

}

if (KeyNum == KEY_Long1)

{

KeyNum = 0;

mode = SETTINGS_MODE;

count_s = 1;

OLED_Clear();

}

Control_Manager();

break;

case MANUAL_MODE:

OLED_manualOption(SetManual());

ManualControl(SetManual());

OLED_manualPage1();

ManualSettingsDisplay1();

if (KeyNum == KEY_1)

{

KeyNum = 0;

mode = AUTO_MODE;

count_a = 1;

OLED_Clear();

}

Control_Manager();

break;

case SETTINGS_MODE:

if (set_flag)

{

set_time = sensorData.calendarData;

set_flag = 0;

location = 1;

count_w = 1;

rtc_get_flag = 0;

}

ThresholdSettings(count_w);

if (KeyNum == KEY_1)

{

KeyNum = 0;

mode = AUTO_MODE;

count_a = 1;

OLED_Clear();

Flag_Writer();

}

break;

default: break;

}

time_num++;

if (time_num % 2 == 0)

delay_ms(10);

if(time_num >= 5000)

{

time_num = 0;

}

}

}

cpp

运行

六、 实验 效果 

 七、包含内容

  项目分享

相关知识

STM32项目分享:智能宠物喂食系统(升级版)
STM32项目分享:智能宠物喂食系统
stm32毕设项目选题大全
STM32单片机蓝牙APP宠物自动喂食器定时语音提醒喂食系统设计
基于STM32单片机设计的宠物喂食监控系统
基于STM32单片机设计的宠物喂食监控系统设计
基于STM32的智能宠物监测自动喂养
STM32项目分享:智能宠物项圈系统
基于STM32的智能宠物喂食系统设计与实现(代码+原理图+APP)
毕业设计基于51/STM32单片机智能鱼缸养殖宠物喂食设计系统成品蓝牙远程(代码+论文)

网址: STM32项目分享:宠物喂食(蓝牙升级版) https://m.mcbbbk.com/newsview1364847.html

所属分类:萌宠日常
上一篇: 哈尔滨宠物殡葬:从流程到费用,你
下一篇: 洛克王国孵蛋再也不用到处找!这个