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: BMP180 N5110 mbed
main.cpp
- Committer:
- orlagilson
- Date:
- 2015-04-30
- Revision:
- 0:2fd314d76f37
- Child:
- 1:1accd82f4281
File content as of revision 0:2fd314d76f37:
#include "mbed.h"
#include "BMP180.h"
#include "N5110.h"
// VCC,SCE,RST,D/C,MOSI,SCLK,LED
N5110 lcd(p7,p8,p9,p10,p11,p13,p26);
// Can also power (VCC) directly from VOUT (3.3 V) -
// Can give better performance due to current limitation from GPIO pin
BMP180 bmp180(p28,p27); // SDA, SCL
Serial serial(USBTX,USBRX);
AnalogIn BUT1(p15);
AnalogIn BUT2(p16);
AnalogIn POT(p20);
int nx=84;
int ny=48;
int i,j;
void clearCells();
void readTemp(){
while(1){
Measurement measurement;
clearCells();
char buffer1[14];
measurement = bmp180.readValues();
int length=sprintf(buffer1,"T = %.2f C",measurement.temperature);
if (length<=14){
lcd.printString(buffer1,10,2);
}
wait(2.0);
}
}
void readPress(){
while(1){
Measurement measurement;
clearCells();
char buffer2[14];
measurement = bmp180.readValues();
int length=sprintf(buffer2,"P = %.2f mb",measurement.pressure);
if (length<=14){
lcd.printString(buffer2,0,2);
}
wait(2.0);
}
}
void menu()
{
while(1) {
lcd.normalMode(); //normal LCD colour mode
lcd.setBrightness(0.5); //LCD backlight set to 50% brightness
if (POT>(2.0/3.0)) {
clearCells();
lcd.printString("Temperature",10,1);
lcd.printString(">",80,2);
lcd.printString("Graph",0,5);
lcd.printString("Current",43,5);
if (BUT1>0.9) { //left button takes the user to the graph option
clearCells();
//tempGraph();
}
if (BUT2>0.9) { //right button takes the user to the current reading
clearCells();
readTemp();
}
}
if ((POT>1.0/3.0)&&(POT<2.0/3.0)) {
clearCells();
lcd.printString("Pressure",20,1);
lcd.printString("<",0,2);
lcd.printString(">",80,2);
lcd.printString("Graph",0,5);
lcd.printString("Current",43,5);
if (BUT1>0.9) {
clearCells();
//pressGraph();
}
if (BUT2>0.9) {
clearCells();
readPress();
}
}
if (POT<(1.0/3.0)) {
clearCells();
lcd.printString("Light",30,1);
lcd.printString("<",0,2);
lcd.printString("Graph",0,5);
lcd.printString("Current",43,5);
if (BUT1>0.9) {
clearCells();
//lightGraph();
}
if (BUT2>0.9) {
clearCells();
//readLight();
}
}
}
}
void clearCells ()
{
//loop through cells and clear
for (int i=0; i<nx; i++) {
for (int j=0; j<ny; j++) {
lcd.clearPixel(i,j);
}
}
lcd.refresh (); //must refresh to write buffer to display
}
int main()
{
lcd.init();
bmp180.init();
menu();
}