Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra function overloads for Strings and Floats #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions SeeedOLED.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,15 @@ void SeeedOLED::putString(const char *String)
}
}

void SeeedOLED::putString(char *String)
{
unsigned char i=0;
while(String[i])
{
putChar(String[i]);
i++;
}
}
unsigned char SeeedOLED::putNumber(long long_num)
{
unsigned char char_buffer[10]="";
Expand Down Expand Up @@ -258,6 +267,65 @@ unsigned char SeeedOLED::putNumber(long long_num)

}

unsigned char SeeedOLED::putFloat(float float_num)
{
unsigned char char_buffer[10]="";
unsigned char i = 0;
unsigned char f = 0;
long long_num = (long)float_num;
int places = 4;

if (long_num < 0)
{
f=1;
putChar('-');
long_num = -long_num;
float_num = -float_num;
}
else if (long_num == 0)
{
f=1;
putChar('0');
return f;
}

while (long_num > 0)
{
char_buffer[i++] = long_num % 10;
long_num /= 10;
}

f=f+i;
for(; i > 0; i--)
{
putChar('0'+ char_buffer[i - 1]);
}

putChar('.');
long_num = (float_num*1000.0)- ((long)float_num*1000);
if (long_num > 0) {
//long_num = 67;//float_num*1000.0;
unsigned char char_buffer_f[10]="";
i = 0;
while (long_num > 0)
{
char_buffer_f[i++] = long_num % 10;
long_num /= 10;
}

f=f+i;
for(; i > 0; i--)
{
putChar('0'+ char_buffer_f[i - 1]);
}

}

return f;

}


void SeeedOLED::drawBitmap(unsigned char *bitmaparray,int bytes)
{
char localAddressMode = addressingMode;
Expand Down
2 changes: 2 additions & 0 deletions SeeedOLED.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ void clearDisplay();
void setBrightness(unsigned char Brightness);
void putChar(unsigned char c);
void putString(const char *String);
void putString(char *String);
unsigned char putNumber(long n);
unsigned char putFloat(float n);

void drawBitmap(unsigned char *bitmaparray,int bytes);

Expand Down