办公室工作环境小助手[外带开饭提醒]-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 5638|回复: 8

[项目] 办公室工作环境小助手[外带开饭提醒]

[复制链接]
发表于 2019-3-25 23:05 | 显示全部楼层 |阅读模式
办公室工作环境小助手[外带开饭提醒]

成品展示


一下是制作过程
01.jpg
选择配件
02.jpg
开始组装
03.jpg
04.jpg
05.jpg
06.jpg
07.jpg
加电测试

温度计.jpg 上图是第一版本,仅仅显示办公室的实时温度
1.jpg
由于每天忘记吃饭时间点,到了食堂就没饭了,增加了一些小功能
升级了一下,添加了一个提示灯,设定了每天11点54份开始点亮
2.jpg
灯亮其后很是有效,我和办公室的同事们再也没有耽误过吃饭的时间
提示灯持续点亮5分钟,防止我们看到了灯亮后还没去,这样就可以彻底解决忘记开饭时间了
3.jpg
12点01分提示灯自动关闭了

每天看着实时的温度,还有到饭点提示的灯光,简单的小制作可以提供很实用的帮助,希望以后可以制作出更多的有实际意义的小制作来~!
游客,如果您要查看本帖隐藏内容请回复

The 1.8" TFT shield
  ----> https://www.adafruit.com/product/802
The 1.44" TFT breakout
  ----> https://www.adafruit.com/product/2088
as well as Adafruit raw 1.8" TFT display
  ----> http://www.adafruit.com/products/618

  Check out the links above for our tutorials and wiring diagrams
  These displays use SPI to communicate, 4 or 5 pins are required to
  interface (RST is optional)
  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.
  MIT license, all text above must be included in any redistribution
****************************************************/
#include <Microduino_Tem_Hum.h>
#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>

//time
#include <Microduino_RTC.h>
#include <TimeLib.h>

//如果开启下面#define set_time的标志,则按照rtcTime中的时间设置RTC模块中的时间
//#define set_time

DateTime rtcTime = {2019, 4, 30, 6, 11, 50, 50};//时间格式(年,月,日,时,分,秒)

RTC rtc;
time_t prevDisplay = 0;



// For the breakout, you can use any 2 or 3 pins
// These pins will also work for the 1.8" TFT shield
Tem_D1  termo;  //调用Sensor-Temperature-D1传感器
#define TFT_CS     D5
#define TFT_RST    -1  // you can also connect this to the Arduino reset
                      // in which case, set this #define pin to -1!
#define TFT_DC     D4

// Option 1 (recommended): must use the hardware SPI pins
// (for UNO thats sclk = 13 and sid = 11) and pin 10 must be
// an output. This is much faster - also required if you want
// to use the microSD card (see the image drawing example)
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS,  TFT_DC, TFT_RST);

// Option 2: use any pins but a little slower!
#define TFT_SCLK D13   // set these to be whatever pins you like!
#define TFT_MOSI D11   // set these to be whatever pins you like!
//Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);


float p = 3.1415926;
String msg = "";
String smsg = "";
String _year = "";
String _month = "";
String _day = "";
String _hour = "";
String _minute = "";
String _second = "";

void setup(void) {
  Serial.begin(9600);
  Serial.print("ST7735 TFT Start");
  Serial.print("Tem_D1:Starting");
  Serial.print(termo.begin());  //初始化温度传感器,并串口打印传感器是否在线
  delay(1000);
  // Use this initializer if you're using a 1.8" TFT
  tft.initR(INITR_BLACKTAB);   // initialize a ST7735S chip, black tab
  tft.setRotation(1);
  // Use this initializer (uncomment) if you're using a 1.44" TFT
  //tft.initR(INITR_144GREENTAB);   // initialize a ST7735S chip, black tab

  // Use this initializer (uncomment) if you're using a 0.96" 180x60 TFT
  //tft.initR(INITR_MINI160x80);   // initialize a ST7735S chip, mini display

  Serial.println("Initialized");

  uint16_t time = millis();
  tft.fillScreen(ST7735_BLACK);
  time = millis() - time;

  Serial.println(time, DEC);
  delay(500);

  // large block of text
  //tft.fillScreen(ST7735_BLACK);
  //testdrawtext("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa, fringilla sed malesuada et, malesuada sit amet turpis. Sed porttitor neque ut ante pretium vitae malesuada nunc bibendum. Nullam aliquet ultrices massa eu hendrerit. Ut sed nisi lorem. In vestibulum purus a tortor imperdiet posuere. ", ST7735_WHITE);
  //delay(1000);

  // tft print function!
  //tftPrintTest();
// delay(4000);



  // optimized lines
  testfastlines(ST7735_RED, ST7735_BLUE);
  delay(500);


  testroundrects();
  tft.println('loading...');
  delay(1000);
  Serial.println("done");
  ///time s
    rtc.begin();
  //如果之前开启了#define set_time的标志,则按照rtcTime中的时间设置RTC模块中的时间
#ifdef set_time
  rtc.clearAll();
  rtc.setDateTime(rtcTime);
#endif
  Serial.println("RTC-time: ");
  rtc.getDateTime(&rtcTime);//获取RTC时间
// serialClockDisplay(rtcTime.year, rtcTime.month, rtcTime.day, rtcTime.hour, rtcTime.minute, rtcTime.second);//打印RTC时间
  setTime(rtcTime.hour, rtcTime.minute, rtcTime.second, rtcTime.day, rtcTime.month, rtcTime.year);//使用RTC时间校准本地时间
//time end

}

void loop() {
    msg=termo.getTemperature();
    Serial.print("Tem_D1 Tem:");
    Serial.println(msg);  //串口打印获取的温度
    Serial.println("------------------");

    Serial.print("onLine:");
    Serial.println(termo.begin());  //串口打印传感器是否在线

  if ((msg!=smsg) and (termo.begin()!=0))
  {
    smsg=msg;
    tft.fillScreen(ST7735_BLACK);
    tft.setCursor(0,10);
    tft.setTextColor(ST7735_RED);
    tft.setTextSize(2);
    tft.println("Temperature");
    tft.setCursor(15,40);
    tft.setTextSize(4);

    tft.setTextColor(ST7735_YELLOW);
    tft.println(smsg);

  }
if (timeStatus() != timeNotSet) {
    //如果本地时间发生变化,则更新串口显示
      if (now() != prevDisplay) {
        prevDisplay = now();
      }
   }
    tft.setCursor(15,80);
    tft.setTextColor(ST7735_RED);
    tft.setTextSize(2);
     _year =year();
     _month =month();
     _day =day();
     _hour =hour();
     _minute =minute();
     _second =second();
    tft.println(_year+"-"+_month+"-"+_day);
    tft.setCursor(15,100);
    tft.setTextColor(ST7735_RED);
    tft.setTextSize(2);
    tft.println(_hour+":"+_minute+":"+_second);
    tft.setCursor(15,100);
    delay(1000);
    tft.setTextColor(ST7735_BLACK);
    tft.setTextSize(2);
    tft.println(_hour+":"+_minute+":"+_second);
    //打开提示灯
    if ((hour()==11)&&(minute()==54)){
      pinMode(6, OUTPUT);
      digitalWrite(6, HIGH);
    }
    //关闭提醒
    if ((hour()==12)&&(minute()==00)){
      digitalWrite(6, LOW);
      pinMode(6, INPUT);
    }
   //************************************************
}

void testlines(uint16_t color) {
  tft.fillScreen(ST7735_BLACK);
  for (int16_t x=0; x < tft.width(); x+=6) {
    tft.drawLine(0, 0, x, tft.height()-1, color);
  }
  for (int16_t y=0; y < tft.height(); y+=6) {
    tft.drawLine(0, 0, tft.width()-1, y, color);
  }

  tft.fillScreen(ST7735_BLACK);
  for (int16_t x=0; x < tft.width(); x+=6) {
    tft.drawLine(tft.width()-1, 0, x, tft.height()-1, color);
  }
  for (int16_t y=0; y < tft.height(); y+=6) {
    tft.drawLine(tft.width()-1, 0, 0, y, color);
  }

  tft.fillScreen(ST7735_BLACK);
  for (int16_t x=0; x < tft.width(); x+=6) {
    tft.drawLine(0, tft.height()-1, x, 0, color);
  }
  for (int16_t y=0; y < tft.height(); y+=6) {
    tft.drawLine(0, tft.height()-1, tft.width()-1, y, color);
  }

  tft.fillScreen(ST7735_BLACK);
  for (int16_t x=0; x < tft.width(); x+=6) {
    tft.drawLine(tft.width()-1, tft.height()-1, x, 0, color);
  }
  for (int16_t y=0; y < tft.height(); y+=6) {
    tft.drawLine(tft.width()-1, tft.height()-1, 0, y, color);
  }
}

void testdrawtext(char *text, uint16_t color) {
  tft.setCursor(0, 0);
  tft.setTextColor(color);
  tft.setTextWrap(true);
  tft.print(text);
}

void testfastlines(uint16_t color1, uint16_t color2) {
  tft.fillScreen(ST7735_BLACK);
  for (int16_t y=0; y < tft.height(); y+=5) {
    tft.drawFastHLine(0, y, tft.width(), color1);
  }
  for (int16_t x=0; x < tft.width(); x+=5) {
    tft.drawFastVLine(x, 0, tft.height(), color2);
  }
}

void testdrawrects(uint16_t color) {
  tft.fillScreen(ST7735_BLACK);
  for (int16_t x=0; x < tft.width(); x+=6) {
    tft.drawRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color);
  }
}

void testfillrects(uint16_t color1, uint16_t color2) {
  tft.fillScreen(ST7735_BLACK);
  for (int16_t x=tft.width()-1; x > 6; x-=6) {
    tft.fillRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color1);
    tft.drawRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color2);
  }
}

void testfillcircles(uint8_t radius, uint16_t color) {
  for (int16_t x=radius; x < tft.width(); x+=radius*2) {
    for (int16_t y=radius; y < tft.height(); y+=radius*2) {
      tft.fillCircle(x, y, radius, color);
    }
  }
}

void testdrawcircles(uint8_t radius, uint16_t color) {
  for (int16_t x=0; x < tft.width()+radius; x+=radius*2) {
    for (int16_t y=0; y < tft.height()+radius; y+=radius*2) {
      tft.drawCircle(x, y, radius, color);
    }
  }
}

void testtriangles() {
  tft.fillScreen(ST7735_BLACK);
  int color = 0xF800;
  int t;
  int w = tft.width()/2;
  int x = tft.height()-1;
  int y = 0;
  int z = tft.width();
  for(t = 0 ; t <= 15; t++) {
    tft.drawTriangle(w, y, y, x, z, x, color);
    x-=4;
    y+=4;
    z-=4;
    color+=100;
  }
}

void testroundrects() {
  tft.fillScreen(ST7735_BLACK);
  int color = 100;
  int i;
  int t;
  for(t = 0 ; t <= 4; t+=1) {
    int x = 0;
    int y = 0;
    int w = tft.width()-2;
    int h = tft.height()-2;
    for(i = 0 ; i <= 16; i+=1) {
      tft.drawRoundRect(x, y, w, h, 5, color);
      x+=2;
      y+=3;
      w-=4;
      h-=6;
      color+=1100;
    }
    color+=100;
  }
}

void tftPrintTest() {
  tft.setTextWrap(false);
  tft.fillScreen(ST7735_BLACK);
  tft.setCursor(0, 30);
  tft.setTextColor(ST7735_RED);
  tft.setTextSize(1);
  tft.println("Hello World!");
  tft.setTextColor(ST7735_YELLOW);
  tft.setTextSize(2);
  tft.println("Hello World!");
  tft.setTextColor(ST7735_GREEN);
  tft.setTextSize(3);
  tft.println("Hello World!");
  tft.setTextColor(ST7735_BLUE);
  tft.setTextSize(4);
  tft.print(1234.567);
  delay(1500);
  tft.setCursor(0, 0);
  tft.fillScreen(ST7735_BLACK);
  tft.setTextColor(ST7735_WHITE);
  tft.setTextSize(0);
  tft.println("Hello World!");
  tft.setTextSize(1);
  tft.setTextColor(ST7735_GREEN);
  tft.print(p, 6);
  tft.println(" Want pi?");
  tft.println(" ");
  tft.print(8675309, HEX); // print 8,675,309 out in HEX!
  tft.println(" Print HEX!");
  tft.println(" ");
  tft.setTextColor(ST7735_WHITE);
  tft.println("Sketch has been");
  tft.println("running for: ");
  tft.setTextColor(ST7735_MAGENTA);
  tft.print(millis() / 1000);
  tft.setTextColor(ST7735_WHITE);
  tft.print(" seconds.");
}

void mediabuttons() {
  // play
  tft.fillScreen(ST7735_BLACK);
  tft.fillRoundRect(25, 10, 78, 60, 8, ST7735_WHITE);
  tft.fillTriangle(42, 20, 42, 60, 90, 40, ST7735_RED);
  delay(500);
  // pause
  tft.fillRoundRect(25, 90, 78, 60, 8, ST7735_WHITE);
  tft.fillRoundRect(39, 98, 20, 45, 5, ST7735_GREEN);
  tft.fillRoundRect(69, 98, 20, 45, 5, ST7735_GREEN);
  delay(500);
  // play color
  tft.fillTriangle(42, 20, 42, 60, 90, 40, ST7735_BLUE);
  delay(50);
  // pause color
  tft.fillRoundRect(39, 98, 20, 45, 5, ST7735_RED);
  tft.fillRoundRect(69, 98, 20, 45, 5, ST7735_RED);
  // play color
  tft.fillTriangle(42, 20, 42, 60, 90, 40, ST7735_GREEN);
}
[/mw_shl_code]




 楼主| 发表于 2019-4-30 23:32 | 显示全部楼层
本帖最后由 冰峰侠 于 2019-5-4 22:57 编辑

代码有一些是屏幕的特效显示函数,故意没删除,以备有需求的朋友使用,至此本项目完成提交了,希望大家喜欢
 楼主| 发表于 2019-6-1 09:59 | 显示全部楼层
欢迎大家来讨论升级和优化,慢慢让他从原型设备变成一个产品
发表于 2019-7-26 19:55 | 显示全部楼层
不错哟!小孩子能做这样很厉害了,几年级??
 楼主| 发表于 2019-7-27 10:57 | 显示全部楼层
这个是孩子爸爸自己做的,给自己吃饭提醒用的孩子提了一些建议,我做了优化
 楼主| 发表于 2019-7-27 10:58 | 显示全部楼层
新手之帆 发表于 2019-7-26 19:55
不错哟!小孩子能做这样很厉害了,几年级??

孩子很喜欢,估计是受我影响,这个作品是我做的,孩子提了一些建议,我做了优化,孩子参加的是另外一个作品。我看着眼馋也参加了一个,但是没有群里的大佬们励害,没有提名,呵呵,下次再接再力
发表于 2019-7-27 13:26 | 显示全部楼层
冰峰侠 发表于 2019-7-27 10:58
孩子很喜欢,估计是受我影响,这个作品是我做的,孩子提了一些建议,我做了优化,孩子参加的是另外一个作 ...

一起加油!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-9-20 22:56 , Processed in 0.112505 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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