赞
踩
看到何同学最新的视频里面出现的办公室标配的提醒喝水的杯垫,感觉很好做,因此就做一个送给女朋友来提醒他按时喝水,项目主要使用了Arduino Nano作为控制器,SSD1306驱动的0.91寸单色OLED作为显示器,屏幕可以显示进度条,以及定制自己想显示的字母或者bmp图片。具体演示效果如下所示。
【WaterRemind】一款何同学视频中出现的提醒喝水杯垫
硬件很简单,具体清单如下
#include <Arduino.h> #include <U8g2lib.h> #include <string.h> #ifdef U8X8_HAVE_HW_SPI #include <SPI.h> #endif #ifdef U8X8_HAVE_HW_I2C #include <Wire.h> #endif U8G2_SSD1306_128X32_UNIVISION_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); // Adafruit Feather ESP8266/32u4 Boards + FeatherWing OLED DS1302 rtc(2, 3, 4); // RST, DAT, CLK Time t1; Time t2; int t3; char tt; int bee = 13; int redPin = A0; int val; #define bmp1_x 80 #define bmp1_y 16 static const unsigned char bmp1[] U8X8_PROGMEM = { 0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x20,0x04,0xE0,0x07,0x00,0x00,0x20,0xF0, 0x01,0x94,0x20,0x04,0x60,0x04,0x02,0x00,0x20,0x60,0xC0,0xD5,0x20,0x1E,0xE7,0x05,0x02,0x24,0x20,0xD0,0x40,0x7C,0xB0,0x14,0x2D,0x07,0x02,0x24,0xA4,0xCC,0xC1,0x7C, 0xB0,0x15,0xED,0xE3,0x1A,0x24,0xA3,0x47,0xC3,0x09,0x30,0x3F,0x97,0x83,0x0E,0x24,0x21,0x01,0x40,0xFC,0x38,0x1C,0xF8,0xC4,0x0E,0x24,0x28,0x04,0x74,0xD5,0x21,0x34, 0xD8,0x48,0x72,0x24,0x38,0xA4,0xED,0x57,0x21,0x66,0xD0,0x29,0xC3,0x64,0x30,0x24,0x19,0xD6,0x21,0x82,0x70,0x0F,0x03,0x44,0x00,0x20,0x00,0x44,0x00,0x02,0xF0,0x05, 0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x02,0x67,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x66,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, }; #define bmp2_x 78 #define bmp2_y 16 static const unsigned char bmp2[] U8X8_PROGMEM = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0xF0,0x01,0x80,0x00,0x08,0xFE,0x00,0x01,0x00,0x00,0x80,0x00,0x80,0x00,0x08,0x18,0x30,0x01,0x00,0x00,0x80,0x00,0x00, 0x01,0x3E,0x18,0x60,0x31,0x00,0xFC,0x83,0x00,0x30,0x01,0x1F,0x3C,0x60,0x1D,0x00,0x00,0xF8,0x0F,0x10,0x01,0x6A,0x76,0x60,0x05,0x00,0x00,0xC0,0x01,0x08,0x02,0xCB, 0xD2,0x30,0x3D,0x00,0x00,0x60,0x03,0x0C,0x06,0x09,0x10,0x08,0x61,0x00,0x00,0x20,0x02,0x04,0x04,0x08,0x10,0x40,0x01,0x00,0x00,0x10,0x06,0x00,0x08,0x00,0x10,0xC0, 0x01,0x00,0x00,0x18,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, }; #define bmp3_x 80 #define bmp3_y 16 static const unsigned char bmp3[] U8X8_PROGMEM = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0xC0,0x03,0x80,0x00, 0x20,0x00,0x3C,0x0F,0xFC,0x0F,0xF8,0x00,0x80,0x79,0x78,0x3E,0xE6,0x09,0x40,0x00,0x80,0x00,0xFC,0x63,0x6E,0x32,0xC3,0x10,0x40,0x00,0x80,0x00,0x94,0x3B,0x7A,0x1A, 0xC1,0x10,0xF0,0x03,0xC0,0x07,0xF4,0x71,0x3F,0x1E,0x01,0x18,0x5C,0x00,0xF0,0x00,0xDC,0x17,0xF8,0x1E,0x01,0x08,0x40,0x0C,0x80,0x0C,0x60,0x14,0x98,0x0A,0x03,0x0C, 0x40,0x18,0x80,0x18,0xF0,0x17,0xF0,0x02,0x06,0x04,0x40,0x16,0x80,0x10,0x40,0x16,0x90,0x02,0x0C,0x02,0xF8,0x7B,0xFC,0x3F,0x80,0x13,0xF0,0x02,0x98,0x01,0x0F,0x80, 0x07,0x00,0x00,0x00,0x00,0x02,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, }; void setup(void) { u8g2.setBusClock(200000); u8g2.begin(); Serial.begin(9600); pinMode(bee,OUTPUT); void loop(void) { int i; char a[10]; val=digitalRead(redPin);//读取模拟接口的值 Serial.println(val);//输出模拟接口的值 Serial.println(rtc.getTimeStr()); u8g2.setFont(u8g2_font_ncenB08_tr); // choose a suitable font if (val==0){ if (t3<180){ u8g2.firstPage(); do{ //放下杯子开始计时 u8g2.clearBuffer(); itoa(t3,tt,10); u8g2.drawXBMP(30,0, bmp2_x, bmp2_y, bmp2); u8g2.drawLine(0, 25, t3*0.55, 25); u8g2.drawLine(0, 26, t3*0.55, 26); u8g2.drawLine(0, 27, t3*0.55, 27); u8g2.drawLine(0, 28, t3*0.55, 28); u8g2.drawLine(0, 29, t3*0.55, 29); u8g2.drawLine(0, 30, t3*0.55, 30); u8g2.drawLine(0, 31, t3*0.55, 31); itoa(t3*0.55,a,10); u8g2.drawStr(100,31,a); u8g2.drawStr(113,31,"%"); t3+=1; }while(u8g2.nextPage()); delay(10000); // } } else{ t3=0; u8g2.clearBuffer(); u8g2.drawXBMP(30,0, bmp1_x, bmp1_y, bmp1); u8g2.sendBuffer(); digitalWrite(bee,HIGH); delay(200); digitalWrite(bee,LOW); delay(50); digitalWrite(bee,HIGH); delay(200); digitalWrite(bee,LOW); delay(100); digitalWrite(bee,HIGH); delay(200); digitalWrite(bee,LOW); delay(50); digitalWrite(bee,HIGH); delay(200); digitalWrite(bee,LOW); delay(100); digitalWrite(bee,HIGH); delay(200); digitalWrite(bee,LOW); delay(50); digitalWrite(bee,HIGH); delay(200); digitalWrite(bee,LOW); delay(10000); u8g2.sendBuffer(); //响 } } else{ //拿起杯子 t3=0; t1 = rtc.getTime(); u8g2.clearBuffer(); u8g2.sendBuffer(); } }
代码需要依赖u8g2库,具体安装方式可以自行在网络搜索
如图,不多解释了
使用pctolcd2002进行取模,字模设置如下图所示。
随后就可以在点阵区域随意发挥了。
外壳模型随意画了一个,已经上传到github:https://github.com/chenziwenhaoshuai/WaterRemind
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。