Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: TextLCD mbed MMA8451Q TSI
MyLCD.cpp
- Committer:
- mfurlanetto
- Date:
- 2015-10-26
- Branch:
- mono
- Revision:
- 16:b3cc7cf41a1b
- Parent:
- 15:b358e700d2d7
File content as of revision 16:b3cc7cf41a1b:
#include "mbed.h"
#include "TextLCD.h"
#include <string>
#ifndef MYLCD
#define MYLCD
class MyLCD
{
public:
MyLCD(int refreshRate, PinName rs, PinName e, PinName d4, PinName d5, PinName d6, PinName d7): lcd(rs, e, d4, d5, d6, d7) {
bufferOld[0]='\0';
if (refreshRate>0)
t.attach(this, &MyLCD::update, 1.0/refreshRate);
else
t.attach(this, &MyLCD::update, 1.0/20);
}
void printf(string text) {
text.copy(buffer, 32, 0 );
buffer[32]='\0';
}
void printf(string text, float number, string nav) {
char tmp2[33];
sprintf(tmp2,text.append(": %.0f\n%s\0").c_str(), number, nav);
printf(tmp2);
}
private:
TextLCD lcd;
Ticker t;
char buffer[33], bufferOld [33];
void update() {
if(!strcmp(bufferOld,buffer)==0) {
lcd.cls();
lcd.printf("%s\0", buffer);
strncpy(bufferOld, buffer, 32);
}
}
};
#endif
