LCD 16x2, www.Sparkfun.com part LCD-09067, serial enabled

Dependencies:   mbed

main.cpp

Committer:
GerritPathuis
Date:
2017-09-22
Revision:
1:c5d938ddc153
Parent:
0:e7b0972dec10
Child:
2:062905d74f97

File content as of revision 1:c5d938ddc153:

#include "mbed.h"
//--- Spark fun part LCD-09067
//-------- LCD 2x26 ----------
// MBED p28-------------------RX
// MBED Vout------------------5V (text on LCD is wrong must be 3,3 Volt)
// MBED GND-------------------GND
// ---------------------------

Serial lcd(p28, p27);       // tx, rx
void clear_lcd(void);
void move_cursor(int, int);

int main() {
    int c=0;
    lcd.baud(9600);
    
    clear_lcd();
    lcd.printf("Hello World");
    wait(1);
    clear_lcd();

    while (1) {
        move_cursor(0,3);
        lcd.printf("pos %02d", c);
        move_cursor(1,3);
        lcd.printf("speed %02d", c);
        c += 1;
    }
}

//------clear the LCD display--------
void clear_lcd(void) {
    lcd.putc(0xFE);
    lcd.putc(0x01);
}

//----------- line 0 or 1----------
//----------- position 0/15--------
// (0,0) is top left position
// (1,15) is bottom right position
void move_cursor(int line, int pos) {
    int cp;
    cp = pos + (line * 64) +128;
    lcd.putc(0xFE);
    lcd.putc(cp);
}