Arduino协助搭建家庭服务器,监控功耗及温度-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 23208|回复: 17

[项目] Arduino协助搭建家庭服务器,监控功耗及温度

[复制链接]
发表于 2017-10-19 22:59 | 显示全部楼层 |阅读模式
本帖最后由 softice 于 2017-10-20 00:35 编辑

起因

作为一名业余的职业码农,家里需要一台服务器,大内存,低功耗,高可用。
网上搜索了很久也没有找到合适的,所以自己动手丰衣足食。
HP的迷之粉丝于是买了一块服务器主板,却没有机箱风扇接口,所以只能依靠其他的芯片给他管理风扇了。
Arduino是个好选择,省电又方便,而且正好赶上大赛,很幸运哈哈哈~



成果

先上成品~ 就是长这个样子:

IMG_4612.jpg




https://www.bilibili.com/video/av15540460/


设计

做一个东西以前,时刻要求自己记得以下的设计十诫,不然容易对不起付出的时间和精力。所以一一核实一下先:

好的设计是创新的 Good design is innovative.
好的设计创造好用的产品 Good design makes a product useful.  
好的设计是符合审美的 Good design is aesthetic.
好的设计帮助我们理解产品 Good design helps us to understand a product.
好的设计是含蓄的 Good design is unobtrusive
好的设计是坦诚的 Good design is honest.
好的设计是耐用的 Good design is durable.
好的设计由最终的细节决定 Good design is consequent to the last detail.
好的设计关注环境 Good design is concerned with the environment.
好的设计是“没有”设计 Good design is as little design as possible.



第一步:冷兵器之纸笔,没有什么比这个更方便了:


IMG_4638.jpg


第二步:构思出来以后,用SketchUp进行细化:


myServer.png


第三步:根据SketchUp的参数,做CAD去订亚克力机箱:


1.png


2.png


CAD图交付的时候,得留意一下是不是有双线的问题,因为如果存在双线,激光头会走两次,那个位置会明显缝隙大。图纸分层做好一些,让卖家做的事情少一些,出现故障的几率就会低一些。



制作

机箱的亚克力到货以前,先来改造一下原来的服务器主板,是HP的DL170e G6主板。为什么家用的东西要选服务器主板?主要有2个因素,一个是支持硬件的远控,另一方面是为了ECC内存和主板元件的排布设计,比较容易设计散热风路。

IMG_4457.jpg


电源也打开看看有没有什么要加的,已经很好了,该有的都有,不过里面有三个大散热片直接靠在了电源的两侧,所以它可能壳会发热,亚克力时间长了可能会变形,所以在下面准备垫一个铁板,两边也空出来位置留给风流过:

IMG_4453.jpg


这个风扇有点吵,是滚珠轴承的风扇,得给它换掉。要静音的话不能选滚珠轴承的风扇,我选的是建准的磁悬浮风扇,只有风噪没有轴承声音,具体可以去建准的网站去找合适的风扇,各种型号的都有。在这个小机箱里比较重要的是风压,需要足够的风压才能让风贯穿机箱。然后最好选PWM调速的风扇,带蓝色的线的那种,因为电压控制转速如果太低容易让风扇直接停转了,PWM就没有这个问题,Arduino也非常好控制,一行命令就可以实现了。


IMG_4454.jpg


硬盘的读写灯准备放在面板上来,主板上的RPC Connector接脚定义实在是没有找到,只好从硬盘下手。硬盘的读写灯是第11引脚,虽然不是标准,但是大部分牌子都支持。文档上写这个接脚不能直接驱动LED,需要外围电路。可以先用这个方法试试看是不是可用先:


hddsataleddiagram1.jpg

图片来自:http://www.tooms.dk/Tblog/Showblog1.asp?BlogID=201111082030033196
确定了PIN11可用,再做电路,我用了第二个,BC557:

schaltplanikcu.jpg 下载.jpg

焊接一个接口把PIN11引出来:

IMG_4458.jpg


电源和主板的铁壳需要紧密合体,拆下主板在它的铁板上打沉孔,特别注意要清理好铁屑:


IMG_4460.jpg


然后在电源的壳上攻丝:


IMG_4463.jpg


拿镀锌板给电源旁边空出来的地方加了个挡片,保证风是从电源内部流过去:


IMG_4472.jpg


上面图中,开孔的位置留给电源插座,又是得攻丝:


IMG_4476.jpg


铁板顺便做了个硬盘架~铁皮很硬,相比铝板的好处是,可以经得住2次弯折,铝的只能一次定型,再弯就会断了。。。


IMG_4477.jpg


里面的是2.5mm厚的EVA泡棉胶带,防震降噪。我肯定不会说这个胶带其实是因为没弄好尺寸,缝隙太大了没办法只好拿泡棉补。


IMG_4473.jpg


亚!克!力!到货啦!很兴奋因为第一次弄亚克力:


IMG_4467.jpg


用亚克力给大赛赞助的Arduino Mega做一个妥妥的架子:


IMG_4483.jpg


已经接了一部分线上去,先测试看看~


IMG_4484.jpg


万万没想到,万万没想到,亚克力粘接是这么痛苦。。。卖家说,我们手工费可贵啊。我说好吧那我回来自己粘。胶水是无影胶,UV固化的,需要在太阳下晒。一直阴天就算了,关键是胶水流的到处都是,很无奈啊,很尴尬啊,很丑陋啊,怎办,硬晒吧,多少有点紫外线吧。我晒了2天,胶还是粘的。同志们,专业的事情还是交给专业的人去做吧,让卖家把壳粘好再发货啊!


IMG_4486.jpg


上面我原来以为是指纹,然而并不是!是胶纹!擦不掉的!


IMG_4492.jpg


痛苦的亚克力先去晾着了,做一下硬盘灯的电路,焊的再丑良心也都不会痛。接头部分用手工暴力压线:


IMG_4480.jpg


已经越来越乱了。。。每次都这么乱,搞的很专业似的,其实没有多少功能啊?


IMG_4482.jpg


测试一下屏幕,屏幕用热熔胶大法直接黏在亚克力的另外一个内壳上了:


IMG_4501.jpg


串口屏,省事,不用控制像素点了,直接画线、写字,很开心~


IMG_4506.jpg


这么乱千万别被什么东西给挂到,再插回去可就难了。。。


IMG_4508.jpg


各种混乱的线之电量模块:


IMG_4513.jpg


电量模块其实淘宝有做好的带屏幕的模块,直接接上就可以了省事极了。但是为了逼格。。。


IMG_4517.jpg


感应的线圈要避免干扰,单独给它准备了一房一厅:


IMG_4518.jpg


把这一大堆线弄整齐是大难题之一,足足折腾了半个晚上:


IMG_4514.jpg


Arduino这边就好办了,扎带大法:


IMG_4521.jpg


1366的老平台,北桥很热很热,原来服务器的风扇可以提供比较高的风量和风压给它散热,但是为了控制噪音,风量没有那么大,所以需要单独的散热风扇,用导热硅胶加铁板直接黏住:


IMG_4522.jpg


临近比赛结束的日子了,亚克力胶还没干。。。熬啊熬啊,终于出太阳了!


IMG_4530.jpg


赶紧晒啊!别人都是晒衣服晒被子,我晒亚克力:


IMG_4528.jpg


工具也晒一下:


IMG_4540.jpg


花花也晒一下:


IMG_4549.jpg


感谢老天爷,胶总算是干了。。。给底壳装铁板:


IMG_4523.jpg


1mm厚的镀锌板,卖家切的尺寸这个准确啊:


IMG_4524.jpg


硬盘部分加避震泡棉胶带:


IMG_4525.jpg


感谢媳妇容忍我这一地东西,我自己看着都闹心:


IMG_4557.jpg


最爱之一当然得出镜一下:


IMG_4560.jpg


开始总装啦:

IMG_4568.jpg


屏幕后面的线整理好,热熔胶大法:


IMG_4569.jpg


Arduino部分的线也整理好,扎带大法:


IMG_4570.jpg


前面的线也弄好了:


IMG_4572.jpg


给底壳加上脚,6mm厚的泡棉胶带:


IMG_4576.jpg


打印面板的标签,挖洞简直要崩溃,好在勉强还可以用:


IMG_4582.jpg


当天组装好已经半夜了,开机起来,透过亚克力,哇奥,美不胜收:


IMG_4586.jpg


星星点点:


IMG_4596.jpg


里面好像一个宫殿:


IMG_4592.jpg


白天再看看:


IMG_4617.jpg


这个位置反光实在是太严重了。。。


IMG_4608.jpg


再来:


IMG_4619.jpg


Arduino安静的在下面:


IMG_4623.jpg


开机,用光线感应控制背光亮度,屏幕下面一点用一片铝箔胶带感应触摸开关屏幕背光:


IMG_4624.jpg


前面的9cm风扇,型号PSD1209PLV2-A,建准的编号很好认,1209表示12v 9cm,后面的V2,V代表磁悬浮轴承,如果是B是滚珠轴承不能选,2代表转速,U是ultra最高,1是高,2是中等。实际上这个风扇在1500转以下,深夜半米远几乎是零噪音,但是也可以转上4000暴力起来,也是只有风噪,强烈推荐建准的磁悬浮风扇用在家里的设备。


IMG_4626.jpg


后面的插座,给Arduino的供电从电源的12v黄线引出来,电源的5v给屏幕,3.3v给其他模块,然后和Arduino的GND连在一起:


IMG_4636.jpg


终于完工,接下来要装系统,让它开始上岗工作了,每天都是美好的一天!


IMG_4629.jpg



源码

Arduino我是新手,代码有很多可以改进的空间,请各位多多指教:

[mw_shl_code=cpp,true]#include <OneWire.h>
#include <DallasTemperature.h>
#include <ZEM004T.h>

// pin settings
#define PIN_MASTERFAN1_SPEED 2
#define PIN_MASTERFAN2_SPEED 3
#define PIN_NORTHFAN_SPEED 21
#define PIN_MASTERFAN_PWM 6
#define PIN_NORTHFAN_PWM 7
#define PIN_ONEWIRE_BUS 22
#define PIN_TOUCHPAD 53
#define PIN_LIGHT_SENSOR 15
#define PIN_SPEAKER 52
#define DELAY_REFRESH 1618
// lcd module: serial1
// power module: serial2

// consts
const int TEMP_CPU_START = 40 * 100;
const int TEMP_CPU_ALERT = 50 * 100;
const int TEMP_CPU_MAX = 60 * 100;
const int TEMP_NORTH_START = 50 * 100;
const int TEMP_NORTH_ALERT = 55 * 100;
const int TEMP_NORTH_MAX = 60 * 100;
const int FAN_SPEED_MIN = 1000;
const long LCD_BACKLIGHT_AUTO_OFF = 5 * 60000;
const int TOUCH_DOUBLE_INTERVAL = 500;

const int CHART_MAX_W = 200;
const int CHART_X_FROM = 209;
const int CHART_X_TO = 377;

const int CHART1_Y_FROM = 51;
const int CHART1_Y_POINTER_FROM = 50;
const int CHART1_Y_TO = 89;
const int CHART1_Y_POINTER_TO = 90;

const int CHART2_Y_FROM = 120;
const int CHART2_Y_POINTER_FROM = 121;
const int CHART2_Y_TO = 144;
const int CHART2_Y_POINTER_TO = 145;

const int CHART3_Y_FROM = 153;
const int CHART3_Y_POINTER_FROM = 154;
const int CHART3_Y_TO = 177;
const int CHART3_Y_POINTER_TO = 178;

const int CHART4_Y_FROM = 185;
const int CHART4_Y_POINTER_FROM = 186;
const int CHART4_Y_TO = 209;
const int CHART4_Y_POINTER_TO = 210;

const String COLOR_RED = "3";
const String COLOR_GREEN = "2";
const String COLOR_WHITE = "1";
const String COLOR_BLACK = "9";

// vars
volatile int fanCounter1 = 0;
volatile int fanCounter2 = 0;
volatile int fanCounter3 = 0;

int chartTempMin = min(TEMP_CPU_START, TEMP_NORTH_START);
int chartTempMax = min(TEMP_CPU_MAX, TEMP_NORTH_MAX);
int chartCurrentX = CHART_X_FROM;
int chartCurrentX1 = CHART_X_FROM + 1;
int chartCurrentY1 = 0;
int chartCurrentY2 = 0;
int chartCurrentY3 = 0;
int chartCurrentY4 = 0;
String chartColor0 = "1";
String chartColor1 = "1";
String chartColor2 = "1";
String chartColor3 = "1";
String fontColor1 = "1";
String fontColor2 = "1";
String fontColor3 = "1";
String fontColor4 = "1";
String fontColor5 = "1";
String fontColor6 = "1";

long millisLogStart = 0;
int logDuration = 0;
int fanRpm1 = 0;
int fanRpm2 = 0;
int fanRpm3 = 0;
int fanPwmMaster = 0;
int fanPwmMaster_pre = 0;
int fanPwmNorth = 0;
int fanPwmNorth_pre = 0;

int tempCpu1 = 0;
int tempCpu2 = 0;
int tempNorth = 0;

int v = 0;
int i = 0;
int p = 0;
int e = 0;

String vStr = "";
String iStr = "";
String pStr = "";
String eStr = "";
String tempCpu1Str = "";
String tempCpu2Str = "";
String tempNorthStr = "";
String fanRpm1Str = "";
String fanRpm2Str = "";
String fanRpm3Str = "";

int envLight = 0;
int envLight_pre = 0;
int lcdBacklight = 1;
int lcdBacklight_pre = 0;
bool bgLightOn = true;
bool isBootBgLight = true;

volatile long millisTouch_this = 0;
volatile long millisTouch_pre = 0;
volatile long millisTouchInterval = 0;
volatile bool singleTouched = false;
volatile bool doubleTouched = false;

long millisBacklightDuration = 0;
long lcdBacklightOn = 0;
String serialPrintBgLight = "";
String serialPrintToggleBorder = "";
char tmpChar = "";
String tmpString = "";

byte tempSensors[4];
bool beep = false;
int alertCount = 0;

OneWire oneWire(PIN_ONEWIRE_BUS);
DallasTemperature Dallas(&oneWire);
PZEM004T pzem(&Serial2);
IPAddress ip(192, 168, 1, 1);

// functions
void count1() {
  fanCounter1++;
}

void count2() {
  fanCounter2++;
}

void count3() {
  fanCounter3++;
}

void genSerialPrintBgLight() {
  lcdBacklight = map(analogRead(PIN_LIGHT_SENSOR), 0, 800, 9, 1);
  if (lcdBacklight != lcdBacklight_pre) {
    bgLightOn = true;
    lcdBacklight_pre = lcdBacklight;
    serialPrintBgLight = "SEBL(" + String(lcdBacklight * 10) + ");";
  } else {
    serialPrintBgLight = "";
  }
}

String  formatDigits_2(int num) {
  String numStr = String(num);
  if (numStr.length() == 2) {
    return numStr;
  } else if (numStr.length() == 1) {
    return "0" + numStr;
  } else {
    return "ER";
  }
}

String  formatDigits_3(int num) {
  String numStr = String(num);
  if (numStr.length() == 3) {
    return numStr;
  } else if (numStr.length() == 2) {
    return "0" + numStr;
  } else if (numStr.length() == 1) {
    return "00" + numStr;
  } else {
    return "ERR";
  }
}

String  formatDigits_4(int num) {
  String numStr = String(num);
  if (numStr.length() == 4) {
    return numStr;
  } else if (numStr.length() == 3) {
    return "0" + numStr;
  } else if (numStr.length() == 2) {
    return "00" + numStr;
  } else if (numStr.length() == 1) {
    return "000" + numStr;
  } else {
    return "ERRO";
  }
}

String  formatDigits_5(int num) {
  String numStr = String(num);
  if (numStr.length() == 5) {
    return numStr;
  } else if (numStr.length() == 4) {
    return "0" + numStr;
  } else if (numStr.length() == 3) {
    return "00" + numStr;
  } else if (numStr.length() == 2) {
    return "000" + numStr;
  } else if (numStr.length() == 1) {
    return "0000" + numStr;
  } else {
    return "ERROR";
  }
}

void LCD_DS(String fontSize, String x, String y, String str, String colorId) {
  Serial1.print("DS");
  Serial1.print(fontSize);
  Serial1.print("(");
  Serial1.print(x);
  Serial1.print(",");
  Serial1.print(y);
  Serial1.print(",'");
  Serial1.print(str);
  Serial1.print("',");
  Serial1.print(colorId);
  Serial1.print(");");
}

void LCD_PL(int x1, int y1, int x2, int y2, String colorId) {
  Serial1.print("L(");
  Serial1.print(x1);
  Serial1.print(",");
  Serial1.print(y1);
  Serial1.print(",");
  Serial1.print(x2);
  Serial1.print(",");
  Serial1.print(y2);
  Serial1.print(",");
  Serial1.print(colorId);
  Serial1.print(");");
}

void LCD_PS(int x, int y, String colorId) {
  Serial1.print("S(");
  Serial1.print(x);
  Serial1.print(",");
  Serial1.print(y);
  Serial1.print(",");
  Serial1.print(colorId);
  Serial1.print(");");
}

void LCD_OFF() {
  if (bgLightOn) {
    bgLightOn = false;
    lcdBacklight_pre = 0;
    Serial1.println("SEBL(0,1);");
  }
}

long map2(long x, long in_min, long in_max, long out_min, long out_max) {
  if (x <= in_min) {
    return out_min;
  } else if (x >= in_max) {
    return out_max;
  } else {
    return map(x, in_min, in_max, out_min, out_max);
  }
}

void setup() {
  pinMode(PIN_MASTERFAN1_SPEED, INPUT);
  pinMode(PIN_MASTERFAN2_SPEED, INPUT);
  pinMode(PIN_NORTHFAN_SPEED, INPUT);
  pinMode(PIN_TOUCHPAD, INPUT);

  pinMode(PIN_MASTERFAN_PWM, OUTPUT);
  pinMode(PIN_NORTHFAN_PWM, OUTPUT);
  pinMode(PIN_SPEAKER, OUTPUT);

  attachInterrupt(digitalPinToInterrupt(PIN_MASTERFAN1_SPEED), count1, RISING);
  attachInterrupt(digitalPinToInterrupt(PIN_MASTERFAN2_SPEED), count2, RISING);
  attachInterrupt(digitalPinToInterrupt(PIN_NORTHFAN_SPEED), count3, RISING);

  Dallas.begin();
  Dallas.getAddress(tempSensors, 0);
  Dallas.setResolution(tempSensors, 9);
  Dallas.setWaitForConversion(false);

  pzem.setAddress(ip);
  Serial1.begin(115200);

  // flash screnn
  genSerialPrintBgLight();
  Serial1.println(serialPrintBgLight);
  delay(3000);
  // special thanks
  Serial1.println("SPG(3);");
  delay(5000);
  // supports
  Serial1.println("SPG(7);");
  delay(3000);

  // show charts
  Serial1.println("SPG(4);");
  String chartRange1 = "0-" + String(CHART_MAX_W) + "W";
  String chartRange2 = String(chartTempMin / 100) + "-" + String(chartTempMax / 100);
  LCD_DS("12", "345", "35", chartRange1, "1");
  LCD_DS("12", "346", "106", chartRange2, "1");
  delay(618);
  Serial1.println("SPG(10);");
  lcdBacklightOn = millis();

  // ignore the first value  
  Dallas.requestTemperatures();

  // finish beep
  digitalWrite(PIN_SPEAKER,HIGH);
  delay(62);
  digitalWrite(PIN_SPEAKER,LOW);
  delay(38);
  digitalWrite(PIN_SPEAKER,HIGH);
  delay(62);
  digitalWrite(PIN_SPEAKER,LOW);
}

void loop () {
  // temperature mudule
  Dallas.requestTemperatures();
  tempCpu1 = Dallas.getTempCByIndex(0);
  tempCpu2 = Dallas.getTempCByIndex(1);
  tempNorth = Dallas.getTempCByIndex(2);

  // power module
  v = pzem.voltage(ip);
  i = round(pzem.current(ip) * 1000);
  p = pzem.power(ip);
  e = round(pzem.energy(ip) / 1000);

  // calc fan speed
  fanCounter1 = 0;
  fanCounter2 = 0;
  fanCounter3 = 0;
  sei();
  delay(DELAY_REFRESH);
  cli();
  fanRpm1 = (30000 / DELAY_REFRESH) * fanCounter1;
  fanRpm2 =  (30000 / DELAY_REFRESH) * fanCounter2;
  fanRpm3 =  (30000 / DELAY_REFRESH) * fanCounter3;

  // pwm
  fanPwmMaster = map2(max(tempCpu1, tempCpu2) * 100, TEMP_CPU_START, TEMP_CPU_MAX, 60, 255);
  fanPwmNorth = map2(tempNorth * 100, TEMP_NORTH_START, TEMP_NORTH_MAX, 60, 255);

  if (fanPwmMaster != fanPwmMaster_pre) {
    analogWrite(PIN_MASTERFAN_PWM, fanPwmMaster);
    //analogWrite(PIN_MASTERFAN2_PWM, fanPwmMaster);
    fanPwmMaster_pre = fanPwmMaster;
  }
  if (fanPwmNorth != fanPwmNorth_pre) {
    analogWrite(PIN_NORTHFAN_PWM, fanPwmNorth);
    fanPwmNorth_pre = fanPwmNorth;
  }

  // color and alert
  if (p >= CHART_MAX_W) {
    chartColor0 = COLOR_RED;
  } else {
    chartColor0 = COLOR_GREEN;
  }
  if (tempCpu1 >= TEMP_CPU_ALERT / 100) {
    fontColor1 = COLOR_RED;
    chartColor1 = COLOR_RED;
    alertCount++;
  } else {
    fontColor1 = COLOR_WHITE;
    chartColor1 = COLOR_GREEN;
  }
  if (tempCpu2 >= TEMP_CPU_ALERT / 100) {
    fontColor2 = COLOR_RED;
    chartColor2 = COLOR_RED;
    alertCount++;
  } else {
    fontColor2 = COLOR_WHITE;
    chartColor2 = COLOR_GREEN;
  }
  if (tempNorth >= TEMP_NORTH_ALERT / 100) {
    fontColor3 = COLOR_RED;
    chartColor3 = COLOR_RED;
    alertCount++;
  } else {
    fontColor3 = COLOR_WHITE;
    chartColor3 = COLOR_GREEN;
  }
  if (fanRpm1 < FAN_SPEED_MIN) {
    fontColor4 = COLOR_RED;
    alertCount++;
  } else {
    fontColor4 = COLOR_WHITE;
  }
  if (fanRpm2 < FAN_SPEED_MIN) {
    fontColor5 = COLOR_RED;
    alertCount++;
  } else {
    fontColor5 = COLOR_WHITE;
  }
  if (fanRpm3 < FAN_SPEED_MIN) {
    fontColor6 = COLOR_RED;
    alertCount++;
  } else {
    fontColor6 = COLOR_WHITE;
  }

  // chart
  chartCurrentX1 = chartCurrentX + 1;
  chartCurrentY1 = map2(p, 0, CHART_MAX_W, CHART1_Y_TO, CHART1_Y_FROM);
  chartCurrentY2 = map2(tempCpu1 * 100, chartTempMin, chartTempMax , CHART2_Y_TO, CHART2_Y_FROM);
  chartCurrentY3 = map2(tempCpu2 * 100, chartTempMin, chartTempMax, CHART3_Y_TO, CHART3_Y_FROM);
  chartCurrentY4 = map2(tempNorth * 100, chartTempMin, chartTempMax, CHART4_Y_TO, CHART4_Y_FROM);

  if (p >= 0)  LCD_DS("64", "17", "39", formatDigits_3(p), "1");
  if (v >= 0) LCD_DS("12", "168", "47", formatDigits_3(v), "1");
  if (i >= 0) LCD_DS("12", "156", "64", formatDigits_5(i), "1");
  if (e >= 0) LCD_DS("12", "156", "81", formatDigits_5(e), "1");

  if (tempCpu1 >= 0) LCD_DS("32", "18", "133", formatDigits_2(tempCpu1), fontColor1);
  if (tempCpu2 >= 0)LCD_DS("32", "78", "133", formatDigits_2(tempCpu2), fontColor2);
  if (tempNorth >= 0)LCD_DS("32", "138", "133", formatDigits_2(tempNorth), fontColor3);

  if (fanRpm1 >= 0) LCD_DS("12", "20", "200", formatDigits_4(fanRpm1), fontColor4);
  if (fanRpm2 >= 0) LCD_DS("12", "80", "200", formatDigits_4(fanRpm2), fontColor5);
  if (fanRpm3 >= 0) LCD_DS("12", "140", "200", formatDigits_4(fanRpm3), fontColor6);

  LCD_PL(chartCurrentX, CHART1_Y_POINTER_FROM, chartCurrentX, chartCurrentY1 - 1, COLOR_BLACK);
  LCD_PL(chartCurrentX, chartCurrentY1, chartCurrentX, CHART1_Y_TO, chartColor0);
  LCD_PL(chartCurrentX1, CHART1_Y_POINTER_FROM, chartCurrentX1, CHART1_Y_POINTER_TO, COLOR_WHITE);
  LCD_PS(chartCurrentX, CHART1_Y_TO + 1, COLOR_BLACK);

  LCD_PL(chartCurrentX, CHART2_Y_POINTER_FROM, chartCurrentX, chartCurrentY2 - 1, COLOR_BLACK);
  LCD_PL(chartCurrentX, chartCurrentY2, chartCurrentX, CHART2_Y_TO, chartColor1);
  LCD_PL(chartCurrentX1, CHART2_Y_POINTER_FROM, chartCurrentX1, CHART2_Y_POINTER_TO, COLOR_WHITE);
  LCD_PS(chartCurrentX, CHART2_Y_TO + 1, COLOR_BLACK);

  LCD_PL(chartCurrentX, CHART3_Y_POINTER_FROM, chartCurrentX, chartCurrentY3 - 1, COLOR_BLACK);
  LCD_PL(chartCurrentX, chartCurrentY3, chartCurrentX, CHART3_Y_TO, chartColor2);
  LCD_PL(chartCurrentX1, CHART3_Y_POINTER_FROM, chartCurrentX1, CHART3_Y_POINTER_TO, COLOR_WHITE);
  LCD_PS(chartCurrentX, CHART3_Y_TO + 1, COLOR_BLACK);

  LCD_PL(chartCurrentX, CHART4_Y_POINTER_FROM, chartCurrentX, chartCurrentY4 - 1, COLOR_BLACK);
  LCD_PL(chartCurrentX, chartCurrentY4, chartCurrentX, CHART4_Y_TO, chartColor3);
  LCD_PL(chartCurrentX1, CHART4_Y_POINTER_FROM, chartCurrentX1, CHART4_Y_POINTER_TO, COLOR_WHITE);
  LCD_PS(chartCurrentX, CHART4_Y_TO + 1, COLOR_BLACK);

  chartCurrentX++;
  if (chartCurrentX > CHART_X_TO) {
    LCD_PL(chartCurrentX, CHART1_Y_POINTER_FROM, chartCurrentX, CHART1_Y_POINTER_TO, COLOR_BLACK);
    LCD_PL(chartCurrentX, CHART2_Y_POINTER_FROM, chartCurrentX, CHART2_Y_POINTER_TO, COLOR_BLACK);
    LCD_PL(chartCurrentX, CHART3_Y_POINTER_FROM, chartCurrentX, CHART3_Y_POINTER_TO, COLOR_BLACK);
    LCD_PL(chartCurrentX, CHART4_Y_POINTER_FROM, chartCurrentX, CHART4_Y_POINTER_TO, COLOR_BLACK);
    chartCurrentX = CHART_X_FROM;
  }

  // backlight
  if (digitalRead(PIN_TOUCHPAD) == HIGH) {
    if (isBootBgLight) {
      isBootBgLight = false;
      lcdBacklight_pre = 0;
    }
    genSerialPrintBgLight();
  } else {
    if (isBootBgLight) {
      millisBacklightDuration = millis() - lcdBacklightOn;
      if (millisBacklightDuration >= LCD_BACKLIGHT_AUTO_OFF || millisBacklightDuration <= 0) {
        LCD_OFF();
      } else {
        genSerialPrintBgLight();
      }
    } else {
      LCD_OFF();
    }
  }

  Serial1.println(serialPrintBgLight);
  interrupts();

  // alert beep
  if (alertCount > 0) {
    digitalWrite(PIN_SPEAKER, HIGH);
    delay(618);
    digitalWrite(PIN_SPEAKER, LOW);
    delay(382);
    digitalWrite(PIN_SPEAKER, HIGH);
    delay(618);
    digitalWrite(PIN_SPEAKER, LOW);
    beep = true;
    alertCount = 0;
  } else {
    if (beep) {
      digitalWrite(PIN_SPEAKER, LOW);
      beep = false;
    }
  }
}

[/mw_shl_code]





参考文档


风扇速度读取:
http://www.theorycircuit.com/reading-dc-fan-rpm-arduino/


硬盘LED改造:
https://gathering.tweakers.net/forum/list_messages/1553800
http://www.tooms.dk/Tblog/Showblog1.asp?BlogID=201111082030033196



感谢Arduino.cn提供的平台,以及KittenBot的硬件支持!

2017-10-19








发表于 2017-10-19 23:27 | 显示全部楼层
好漂亮的外观啊~
发表于 2017-10-20 09:27 | 显示全部楼层
这已经不是业余水平了
发表于 2017-10-20 17:25 | 显示全部楼层
会CAD果然也是一大优势
 楼主| 发表于 2017-10-22 00:15 | 显示全部楼层
syl312 发表于 2017-10-19 23:27
好漂亮的外观啊~

谢谢鼓励!
 楼主| 发表于 2017-10-22 00:15 | 显示全部楼层
单片机菜鸟 发表于 2017-10-20 09:27
这已经不是业余水平了

其实是相机的功劳比较大
 楼主| 发表于 2017-10-22 00:17 | 显示全部楼层
猫尾草 发表于 2017-10-20 17:25
会CAD果然也是一大优势

被逼无奈。。。现在订点什么都是激光切割,都得CAD图纸。。
 楼主| 发表于 2017-10-22 00:22 | 显示全部楼层
机器开始服役,发现一些问题,就是原来源码里,风扇的控制不够连续,例如CPU从42上升到43度,风扇因为提速,声音变化比较突兀,夜深人静工作的时候,会被转移注意力。所以修改了下源码,把风扇的速度变化的时候过度的更柔和,用最近10次温度的移动平均来做控制。

新的代码:


定义部分:
[mw_shl_code=bash,true]const int TEMP_AVG_CYCLE = 10;

int tempCpuAvg[TEMP_AVG_CYCLE];
int tempNorthAvg[TEMP_AVG_CYCLE];
long tempCpuAvgTotal;
long tempNorthAvgTotal;
int avgIndex = 0;[/mw_shl_code]


loop函数中PWM部分:

[mw_shl_code=cpp,true]  // pwm
  tempCpuAvgTotal = 0;
  tempNorthAvgTotal = 0;
  tempCpuAvg[avgIndex] = max(tempCpu1, tempCpu2) * 100;
  tempNorthAvg[avgIndex] = tempNorth * 100;
  avgIndex++;
  if (avgIndex >= TEMP_AVG_CYCLE) {
    avgIndex = 0;
  }
  for ( int i = 0; i < TEMP_AVG_CYCLE; ++i ) {
    tempCpuAvgTotal += tempCpuAvg;
    tempNorthAvgTotal += tempNorthAvg;
  }

  fanPwmMaster = map2(tempCpuAvgTotal / TEMP_AVG_CYCLE, TEMP_CPU_START, TEMP_CPU_MAX, 0, 254);
  fanPwmNorth = map2(tempNorthAvgTotal / TEMP_AVG_CYCLE, TEMP_NORTH_START, TEMP_NORTH_MAX, 0, 254);

  if (fanPwmMaster != fanPwmMaster_pre) {
    analogWrite(PIN_MASTERFAN_PWM, fanPwmMaster);
    //analogWrite(PIN_MASTERFAN2_PWM, fanPwmMaster);
    fanPwmMaster_pre = fanPwmMaster;
  }
  if (fanPwmNorth != fanPwmNorth_pre) {
    analogWrite(PIN_NORTHFAN_PWM, fanPwmNorth);
    fanPwmNorth_pre = fanPwmNorth;
  }[/mw_shl_code]




完整代码:
[mw_shl_code=cpp,true]#include <OneWire.h>
#include <DallasTemperature.h>
#include <PZEM004T.h>

// pin settings
#define PIN_MASTERFAN1_SPEED 2
#define PIN_MASTERFAN2_SPEED 3
#define PIN_NORTHFAN_SPEED 21
#define PIN_MASTERFAN_PWM 6
#define PIN_NORTHFAN_PWM 7
#define PIN_ONEWIRE_BUS 22
#define PIN_TOUCHPAD 53
#define PIN_LIGHT_SENSOR 15
#define PIN_SPEAKER 52
#define DELAY_REFRESH 1618
// lcd module: serial1
// power module: serial2

// consts
const int TEMP_CPU_START = 35 * 100;
const int TEMP_CPU_ALERT = 50 * 100;
const int TEMP_CPU_MAX = 55 * 100;
const int TEMP_NORTH_START = 40 * 100;
const int TEMP_NORTH_ALERT = 50 * 100;
const int TEMP_NORTH_MAX = 55 * 100;
const int TEMP_AVG_CYCLE = 10;
const int FAN_SPEED_MIN = 1000;
const long LCD_BACKLIGHT_AUTO_OFF = 5 * 60000;

const int CHART_MAX_W = 200;
const int CHART_X_FROM = 209;
const int CHART_X_TO = 377;

const int CHART1_Y_FROM = 51;
const int CHART1_Y_POINTER_FROM = 50;
const int CHART1_Y_TO = 89;
const int CHART1_Y_POINTER_TO = 90;

const int CHART2_Y_FROM = 120;
const int CHART2_Y_POINTER_FROM = 121;
const int CHART2_Y_TO = 144;
const int CHART2_Y_POINTER_TO = 145;

const int CHART3_Y_FROM = 153;
const int CHART3_Y_POINTER_FROM = 154;
const int CHART3_Y_TO = 177;
const int CHART3_Y_POINTER_TO = 178;

const int CHART4_Y_FROM = 185;
const int CHART4_Y_POINTER_FROM = 186;
const int CHART4_Y_TO = 209;
const int CHART4_Y_POINTER_TO = 210;

const String COLOR_RED = "3";
const String COLOR_GREEN = "2";
const String COLOR_WHITE = "1";
const String COLOR_BLACK = "9";

// vars
volatile int fanCounter1 = 0;
volatile int fanCounter2 = 0;
volatile int fanCounter3 = 0;

int chartTempMin = min(TEMP_CPU_START, TEMP_NORTH_START);
int chartTempMax = min(TEMP_CPU_MAX, TEMP_NORTH_MAX);
int chartCurrentX = CHART_X_FROM;
int chartCurrentX1 = CHART_X_FROM + 1;
int chartCurrentY1 = 0;
int chartCurrentY2 = 0;
int chartCurrentY3 = 0;
int chartCurrentY4 = 0;
String chartColor0 = "1";
String chartColor1 = "1";
String chartColor2 = "1";
String chartColor3 = "1";
String fontColor1 = "1";
String fontColor2 = "1";
String fontColor3 = "1";
String fontColor4 = "1";
String fontColor5 = "1";
String fontColor6 = "1";

long millisLogStart = 0;
int logDuration = 0;
int fanRpm1 = 0;
int fanRpm2 = 0;
int fanRpm3 = 0;
int fanPwmMaster = 0;
int fanPwmMaster_pre = 0;
int fanPwmNorth = 0;
int fanPwmNorth_pre = 0;

int tempCpu1 = 0;
int tempCpu2 = 0;
int tempNorth = 0;

int tempCpuAvg[TEMP_AVG_CYCLE];
int tempNorthAvg[TEMP_AVG_CYCLE];
long tempCpuAvgTotal;
long tempNorthAvgTotal;
int avgIndex = 0;

int v = 0;
int i = 0;
int p = 0;
int e = 0;

String vStr = "";
String iStr = "";
String pStr = "";
String eStr = "";
String tempCpu1Str = "";
String tempCpu2Str = "";
String tempNorthStr = "";
String fanRpm1Str = "";
String fanRpm2Str = "";
String fanRpm3Str = "";

int envLight = 0;
int envLight_pre = 0;
int lcdBacklight = 1;
int lcdBacklight_pre = 0;
bool bgLightOn = true;
bool isBootBgLight = true;

volatile long millisTouch_this = 0;
volatile long millisTouch_pre = 0;
volatile long millisTouchInterval = 0;
volatile bool singleTouched = false;
volatile bool doubleTouched = false;

long millisBacklightDuration = 0;
long lcdBacklightOn = 0;
String serialPrintBgLight = "";
String serialPrintToggleBorder = "";
char tmpChar = "";
String tmpString = "";

byte tempSensors[4];
bool beep = false;
int alertCount = 0;

OneWire oneWire(PIN_ONEWIRE_BUS);
DallasTemperature Dallas(&oneWire);
PZEM004T pzem(&Serial2);
IPAddress ip(192, 168, 1, 1);

// functions
void count1() {
  fanCounter1++;
}

void count2() {
  fanCounter2++;
}

void count3() {
  fanCounter3++;
}

void genSerialPrintBgLight() {
  lcdBacklight = map(analogRead(PIN_LIGHT_SENSOR), 0, 800, 9, 1);
  if (lcdBacklight != lcdBacklight_pre) {
    bgLightOn = true;
    lcdBacklight_pre = lcdBacklight;
    serialPrintBgLight = "SEBL(" + String(lcdBacklight * 10) + ");";
  } else {
    serialPrintBgLight = "";
  }
}

String  formatDigits_2(int num) {
  String numStr = String(num);
  if (numStr.length() == 2) {
    return numStr;
  } else if (numStr.length() == 1) {
    return "0" + numStr;
  } else {
    return "ER";
  }
}

String  formatDigits_3(int num) {
  String numStr = String(num);
  if (numStr.length() == 3) {
    return numStr;
  } else if (numStr.length() == 2) {
    return "0" + numStr;
  } else if (numStr.length() == 1) {
    return "00" + numStr;
  } else {
    return "ERR";
  }
}

String  formatDigits_4(int num) {
  String numStr = String(num);
  if (numStr.length() == 4) {
    return numStr;
  } else if (numStr.length() == 3) {
    return "0" + numStr;
  } else if (numStr.length() == 2) {
    return "00" + numStr;
  } else if (numStr.length() == 1) {
    return "000" + numStr;
  } else {
    return "ERRO";
  }
}

String  formatDigits_5(int num) {
  String numStr = String(num);
  if (numStr.length() == 5) {
    return numStr;
  } else if (numStr.length() == 4) {
    return "0" + numStr;
  } else if (numStr.length() == 3) {
    return "00" + numStr;
  } else if (numStr.length() == 2) {
    return "000" + numStr;
  } else if (numStr.length() == 1) {
    return "0000" + numStr;
  } else {
    return "ERROR";
  }
}

void LCD_DS(String fontSize, String x, String y, String str, String colorId) {
  Serial1.print("DS");
  Serial1.print(fontSize);
  Serial1.print("(");
  Serial1.print(x);
  Serial1.print(",");
  Serial1.print(y);
  Serial1.print(",'");
  Serial1.print(str);
  Serial1.print("',");
  Serial1.print(colorId);
  Serial1.print(");");
}

void LCD_PL(int x1, int y1, int x2, int y2, String colorId) {
  Serial1.print("PL(");
  Serial1.print(x1);
  Serial1.print(",");
  Serial1.print(y1);
  Serial1.print(",");
  Serial1.print(x2);
  Serial1.print(",");
  Serial1.print(y2);
  Serial1.print(",");
  Serial1.print(colorId);
  Serial1.print(");");
}

void LCD_PS(int x, int y, String colorId) {
  Serial1.print("PS(");
  Serial1.print(x);
  Serial1.print(",");
  Serial1.print(y);
  Serial1.print(",");
  Serial1.print(colorId);
  Serial1.print(");");
}

void LCD_OFF() {
  if (bgLightOn) {
    bgLightOn = false;
    lcdBacklight_pre = 0;
    Serial1.println("SEBL(0,1);");
  }
}

long map2(long x, long in_min, long in_max, long out_min, long out_max) {
  if (x <= in_min) {
    return out_min;
  } else if (x >= in_max) {
    return out_max;
  } else {
    return map(x, in_min, in_max, out_min, out_max);
  }
}

void setup() {
  pinMode(PIN_MASTERFAN1_SPEED, INPUT);
  pinMode(PIN_MASTERFAN2_SPEED, INPUT);
  pinMode(PIN_NORTHFAN_SPEED, INPUT);
  pinMode(PIN_TOUCHPAD, INPUT);

  pinMode(PIN_MASTERFAN_PWM, OUTPUT);
  pinMode(PIN_NORTHFAN_PWM, OUTPUT);
  pinMode(PIN_SPEAKER, OUTPUT);

  attachInterrupt(digitalPinToInterrupt(PIN_MASTERFAN1_SPEED), count1, RISING);
  attachInterrupt(digitalPinToInterrupt(PIN_MASTERFAN2_SPEED), count2, RISING);
  attachInterrupt(digitalPinToInterrupt(PIN_NORTHFAN_SPEED), count3, RISING);

  Dallas.begin();
  Dallas.getAddress(tempSensors, 0);
  Dallas.setResolution(tempSensors, 9);
  Dallas.setWaitForConversion(false);

  // tempAvg init
  for ( int i = 0; i < TEMP_AVG_CYCLE; ++i ) {
    tempCpuAvg = 0;
  }

  pzem.setAddress(ip);
  Serial1.begin(115200);

  // flash screnn
  genSerialPrintBgLight();
  Serial1.println(serialPrintBgLight);
  delay(3000);
  // special thanks
  Serial1.println("SPG(3);");
  delay(5000);
  // supports
  Serial1.println("SPG(7);");
  delay(3000);

  // show charts
  Serial1.println("SPG(4);");
  String chartRange1 = "0-" + String(CHART_MAX_W) + "W";
  String chartRange2 = String(chartTempMin / 100) + "-" + String(chartTempMax / 100);
  LCD_DS("12", "345", "35", chartRange1, "1");
  LCD_DS("12", "346", "106", chartRange2, "1");
  delay(618);
  Serial1.println("SPG(10);");
  lcdBacklightOn = millis();

  // ignore the first value
  Dallas.requestTemperatures();

  // finish beep
  digitalWrite(PIN_SPEAKER, HIGH);
  delay(62);
  digitalWrite(PIN_SPEAKER, LOW);
}

void loop () {
  // temperature mudule
  Dallas.requestTemperatures();
  tempCpu1 = Dallas.getTempCByIndex(0);
  tempCpu2 = Dallas.getTempCByIndex(1);
  tempNorth = Dallas.getTempCByIndex(2);

  // power module
  v = pzem.voltage(ip);
  i = round(pzem.current(ip) * 1000);
  p = pzem.power(ip);
  e = round(pzem.energy(ip) / 1000);

  // calc fan speed
  fanCounter1 = 0;
  fanCounter2 = 0;
  fanCounter3 = 0;
  sei();
  delay(DELAY_REFRESH);
  cli();
  fanRpm1 = (30000 / DELAY_REFRESH) * fanCounter1;
  fanRpm2 =  (30000 / DELAY_REFRESH) * fanCounter2;
  fanRpm3 =  (30000 / DELAY_REFRESH) * fanCounter3;

  // pwm
  tempCpuAvgTotal = 0;
  tempNorthAvgTotal = 0;
  tempCpuAvg[avgIndex] = max(tempCpu1, tempCpu2) * 100;
  tempNorthAvg[avgIndex] = tempNorth * 100;
  avgIndex++;
  if (avgIndex >= TEMP_AVG_CYCLE) {
    avgIndex = 0;
  }
  for ( int i = 0; i < TEMP_AVG_CYCLE; ++i ) {
    tempCpuAvgTotal += tempCpuAvg;
    tempNorthAvgTotal += tempNorthAvg;
  }

  fanPwmMaster = map2(tempCpuAvgTotal / TEMP_AVG_CYCLE, TEMP_CPU_START, TEMP_CPU_MAX, 0, 254);
  fanPwmNorth = map2(tempNorthAvgTotal / TEMP_AVG_CYCLE, TEMP_NORTH_START, TEMP_NORTH_MAX, 0, 254);

  if (fanPwmMaster != fanPwmMaster_pre) {
    analogWrite(PIN_MASTERFAN_PWM, fanPwmMaster);
    //analogWrite(PIN_MASTERFAN2_PWM, fanPwmMaster);
    fanPwmMaster_pre = fanPwmMaster;
  }
  if (fanPwmNorth != fanPwmNorth_pre) {
    analogWrite(PIN_NORTHFAN_PWM, fanPwmNorth);
    fanPwmNorth_pre = fanPwmNorth;
  }

  // color and alert
  if (p >= CHART_MAX_W) {
    chartColor0 = COLOR_RED;
  } else {
    chartColor0 = COLOR_GREEN;
  }
  if (tempCpu1 >= TEMP_CPU_ALERT / 100) {
    fontColor1 = COLOR_RED;
    chartColor1 = COLOR_RED;
    alertCount++;
  } else {
    fontColor1 = COLOR_WHITE;
    chartColor1 = COLOR_GREEN;
  }
  if (tempCpu2 >= TEMP_CPU_ALERT / 100) {
    fontColor2 = COLOR_RED;
    chartColor2 = COLOR_RED;
    alertCount++;
  } else {
    fontColor2 = COLOR_WHITE;
    chartColor2 = COLOR_GREEN;
  }
  if (tempNorth >= TEMP_NORTH_ALERT / 100) {
    fontColor3 = COLOR_RED;
    chartColor3 = COLOR_RED;
    alertCount++;
  } else {
    fontColor3 = COLOR_WHITE;
    chartColor3 = COLOR_GREEN;
  }
  if (fanRpm1 < FAN_SPEED_MIN) {
    fontColor4 = COLOR_RED;
    alertCount++;
  } else {
    fontColor4 = COLOR_WHITE;
  }
  if (fanRpm2 < FAN_SPEED_MIN) {
    fontColor5 = COLOR_RED;
    alertCount++;
  } else {
    fontColor5 = COLOR_WHITE;
  }
  if (fanRpm3 < FAN_SPEED_MIN) {
    fontColor6 = COLOR_RED;
    alertCount++;
  } else {
    fontColor6 = COLOR_WHITE;
  }

  // chart
  chartCurrentX1 = chartCurrentX + 1;
  chartCurrentY1 = map2(p, 0, CHART_MAX_W, CHART1_Y_TO, CHART1_Y_FROM);
  chartCurrentY2 = map2(tempCpu1 * 100, chartTempMin, chartTempMax , CHART2_Y_TO, CHART2_Y_FROM);
  chartCurrentY3 = map2(tempCpu2 * 100, chartTempMin, chartTempMax, CHART3_Y_TO, CHART3_Y_FROM);
  chartCurrentY4 = map2(tempNorth * 100, chartTempMin, chartTempMax, CHART4_Y_TO, CHART4_Y_FROM);

  if (p >= 0)  LCD_DS("64", "17", "39", formatDigits_3(p), "1");
  if (v >= 0) LCD_DS("12", "168", "47", formatDigits_3(v), "1");
  if (i >= 0) LCD_DS("12", "156", "64", formatDigits_5(i), "1");
  if (e >= 0) LCD_DS("12", "156", "81", formatDigits_5(e), "1");

  if (tempCpu1 >= 0) LCD_DS("32", "18", "133", formatDigits_2(tempCpu1), fontColor1);
  if (tempCpu2 >= 0)LCD_DS("32", "78", "133", formatDigits_2(tempCpu2), fontColor2);
  if (tempNorth >= 0)LCD_DS("32", "138", "133", formatDigits_2(tempNorth), fontColor3);

  if (fanRpm1 >= 0) LCD_DS("12", "20", "200", formatDigits_4(fanRpm1), fontColor4);
  if (fanRpm2 >= 0) LCD_DS("12", "80", "200", formatDigits_4(fanRpm2), fontColor5);
  if (fanRpm3 >= 0) LCD_DS("12", "140", "200", formatDigits_4(fanRpm3), fontColor6);

  LCD_PL(chartCurrentX, CHART1_Y_POINTER_FROM, chartCurrentX, chartCurrentY1 - 1, COLOR_BLACK);
  LCD_PL(chartCurrentX, chartCurrentY1, chartCurrentX, CHART1_Y_TO, chartColor0);
  LCD_PL(chartCurrentX1, CHART1_Y_POINTER_FROM, chartCurrentX1, CHART1_Y_POINTER_TO, COLOR_WHITE);
  LCD_PS(chartCurrentX, CHART1_Y_TO + 1, COLOR_BLACK);

  LCD_PL(chartCurrentX, CHART2_Y_POINTER_FROM, chartCurrentX, chartCurrentY2 - 1, COLOR_BLACK);
  LCD_PL(chartCurrentX, chartCurrentY2, chartCurrentX, CHART2_Y_TO, chartColor1);
  LCD_PL(chartCurrentX1, CHART2_Y_POINTER_FROM, chartCurrentX1, CHART2_Y_POINTER_TO, COLOR_WHITE);
  LCD_PS(chartCurrentX, CHART2_Y_TO + 1, COLOR_BLACK);

  LCD_PL(chartCurrentX, CHART3_Y_POINTER_FROM, chartCurrentX, chartCurrentY3 - 1, COLOR_BLACK);
  LCD_PL(chartCurrentX, chartCurrentY3, chartCurrentX, CHART3_Y_TO, chartColor2);
  LCD_PL(chartCurrentX1, CHART3_Y_POINTER_FROM, chartCurrentX1, CHART3_Y_POINTER_TO, COLOR_WHITE);
  LCD_PS(chartCurrentX, CHART3_Y_TO + 1, COLOR_BLACK);

  LCD_PL(chartCurrentX, CHART4_Y_POINTER_FROM, chartCurrentX, chartCurrentY4 - 1, COLOR_BLACK);
  LCD_PL(chartCurrentX, chartCurrentY4, chartCurrentX, CHART4_Y_TO, chartColor3);
  LCD_PL(chartCurrentX1, CHART4_Y_POINTER_FROM, chartCurrentX1, CHART4_Y_POINTER_TO, COLOR_WHITE);
  LCD_PS(chartCurrentX, CHART4_Y_TO + 1, COLOR_BLACK);

  chartCurrentX++;
  if (chartCurrentX > CHART_X_TO) {
    LCD_PL(chartCurrentX, CHART1_Y_POINTER_FROM, chartCurrentX, CHART1_Y_POINTER_TO, COLOR_BLACK);
    LCD_PL(chartCurrentX, CHART2_Y_POINTER_FROM, chartCurrentX, CHART2_Y_POINTER_TO, COLOR_BLACK);
    LCD_PL(chartCurrentX, CHART3_Y_POINTER_FROM, chartCurrentX, CHART3_Y_POINTER_TO, COLOR_BLACK);
    LCD_PL(chartCurrentX, CHART4_Y_POINTER_FROM, chartCurrentX, CHART4_Y_POINTER_TO, COLOR_BLACK);
    chartCurrentX = CHART_X_FROM;
  }

  // backlight
  if (digitalRead(PIN_TOUCHPAD) == HIGH) {
    if (isBootBgLight) {
      isBootBgLight = false;
      lcdBacklight_pre = 0;
    }
    genSerialPrintBgLight();
  } else {
    if (isBootBgLight) {
      millisBacklightDuration = millis() - lcdBacklightOn;
      if (millisBacklightDuration >= LCD_BACKLIGHT_AUTO_OFF || millisBacklightDuration <= 0) {
        LCD_OFF();
        isBootBgLight = false;
      } else {
        genSerialPrintBgLight();
      }
    } else {
      LCD_OFF();
    }
  }

  Serial1.println(serialPrintBgLight);
  interrupts();

  // alert beep
  if (alertCount > 0) {
    digitalWrite(PIN_SPEAKER, HIGH);
    delay(618);
    digitalWrite(PIN_SPEAKER, LOW);
    delay(382);
    digitalWrite(PIN_SPEAKER, HIGH);
    delay(618);
    digitalWrite(PIN_SPEAKER, LOW);
    beep = true;
    alertCount = 0;
  } else {
    if (beep) {
      digitalWrite(PIN_SPEAKER, LOW);
      beep = false;
    }
  }
}

[/mw_shl_code]

发表于 2017-10-22 22:24 | 显示全部楼层
1.感谢对社区比赛的支持,开发者积分和贡献值已发放,请点击以下链接领取纪念衫并参与抽奖~
http://www.arduino.cn/thread-48132-1-1.html
2.比赛结果会在11.15号前公布,请耐心等待。
发表于 2017-11-6 22:49 | 显示全部楼层
服务器用着如何?
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2024-11-28 02:42 , Processed in 0.103869 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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