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-19
- Branch:
- mono
- Revision:
- 12:47ba147bcbb7
- Parent:
- 11:97e964c9eeb2
- Child:
- 15:b358e700d2d7
File content as of revision 12:47ba147bcbb7:
#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) {
if (refreshRate>0)
t.attach(this, &MyLCD::update, 1.0/refreshRate);
else
t.attach(this, &MyLCD::update, 1.0/20);
}
void printf(string text) {
strcpy (buffer,text.c_str());
}
void printf(string text, float number, string nav) {
const char *tmp2 = text.append(": %.1f\n%s").c_str();
sprintf(buffer, tmp2, number, nav);
}
private:
TextLCD lcd;
Ticker t;
char buffer[33], bufferOld [33];
void update() {
if(!strcmp(bufferOld,buffer)==0) {
lcd.cls();
lcd.printf("%s", buffer);
strcpy(bufferOld, buffer);
}
}
};
#endif
