Last active
January 7, 2019 13:58
-
-
Save simonliu009/128fd46155f66681a255d1000d767aec to your computer and use it in GitHub Desktop.
C++: Extracting individual digits from a float for LCD1602 number display, 从浮点数提取每一位的数字的函数实现,用于LCD1602显示,STM, Arduino,#c #LCD1602 #c++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "math.h" | |
int getDigits(float d, int digits) | |
{ | |
int tempint = (int)(d / pow(10.0, digits - 1)); | |
return (tempint % 10); | |
} | |
PM25Data[0] = (PM25data/10000)%10 + 0x30; | |
PM25Data[1] = (PM25data/1000)%10 + 0x30; | |
PM25Data[2] = (PM25data/100)%10 + 0x30; | |
PM25Data[3] = (PM25data/10)%10 + 0x30; | |
PM25Data[4] = 0x2E; | |
PM25Data[5] = PM25data%10 + 0x30; | |
PM25Data[6] = '\0'; | |
if(PM25Data[0] == 0x30) | |
{ | |
PM25Data[0] = 0x20; //替换为空格显示 | |
if(PM25Data[1] == 0x30) | |
{ | |
PM25Data[1] = 0x20; | |
if(PM25Data[2] == 0x30) | |
{ | |
PM25Data[2] = 0x20; | |
if(PM25Data[3] == 0x30) | |
{ | |
PM25Data[3] = 0x20; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment