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-18
- Branch:
- mono
- Revision:
- 11:97e964c9eeb2
- Child:
- 12:47ba147bcbb7
File content as of revision 11:97e964c9eeb2:
#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) {
        lcd.printf("%d Hz, %.3f s", refreshRate, 1.0/refreshRate);
        wait(3);
        i=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) {
        strcpy (buffer,text.c_str());
    }
    void printf(string text, float number) {
        const char *tmp2 = text.append(": %.1f").c_str();
        sprintf(buffer, tmp2, number);
    }
private:
    TextLCD lcd;
    int i;
    Ticker t;
    char buffer[33], bufferOld [33];
    void update() {
        if(!strcmp(bufferOld,buffer)==0) {
            lcd.cls();
            lcd.printf("%s", buffer);
            strcpy(bufferOld, buffer);
        }
    }
};
#endif
            
    