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-05-07
- Revision:
- 5:3246c4b8362c
- Parent:
- 4:0302731434a5
- Child:
- 6:1b5603fd1a9c
File content as of revision 5:3246c4b8362c:
#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
InterruptIn buttonleft(p15);
AnalogIn BUT2(p16);
AnalogIn POT(p20);
DigitalOut led(p25);
int nx=84;
int ny=48;
int i,j;
float temperature;
float pressure;
int buttonFlag=0;
void clearCells();
void menu();
Timeout callT;
Timeout callP;
Ticker timerT;
Ticker timerP;
Ticker timerE;
int timerTFlag = 0;
int timerPFlag = 0;
int timerEFlag = 0;
void timerTExpired(){
timerTFlag = 1;
}
void timerPExpired(){
timerPFlag = 1;
}
void timerEExpired(){
timerEFlag = 1;
}
void buttonPressed(){
buttonFlag=1;
}
void error(){
timerE.attach(&timerEExpired,2.0);
while(1){
if (timerEFlag){
timerEFlag=0;
led=1;
wait(1.0);
led=0;
}
}
}
void callTemp(){
Measurement measurement;
clearCells();
lcd.printString("Menu",0,5);
char bufferT[14];
measurement = bmp180.readValues();
int length=sprintf(bufferT,"T = %.2f C",measurement.temperature);
if (length<=14){
lcd.printString(bufferT,10,2);
}
}
void callPress(){
Measurement measurement;
clearCells();
lcd.printString("Menu",0,5);
char bufferP[14];
measurement = bmp180.readValues();
int length=sprintf(bufferP,"P = %.2f mb",measurement.pressure);
if (length<=14){
lcd.printString(bufferP,0,2);
}
}
void readTemp(){
callT.attach(&callTemp,0.1);
timerT.attach(&timerTExpired,60);
while(1){
if (timerTFlag){
timerTFlag=0;
Measurement measurement;
clearCells();
lcd.printString("Menu",0,5);
char bufferT[14];
measurement = bmp180.readValues();
int length=sprintf(bufferT,"T = %.2f C",measurement.temperature);
if (length<=14){
lcd.printString(bufferT,10,2);
}
}
if (buttonFlag){
buttonFlag=0;
menu();
}
}
}
void readPress(){
callP.attach(&callPress,0.1);
timerP.attach(&timerPExpired,1800);
while(1){
if (timerPFlag){
timerPFlag=0;
Measurement measurement;
clearCells();
lcd.printString("Menu",0,5);
char bufferP[14];
measurement = bmp180.readValues();
int length=sprintf(bufferP,"P = %.2f mb",measurement.pressure);
if (length<=14){
lcd.printString(bufferP,0,2);
}
}
if (buttonFlag){
buttonFlag=0;
menu();
}
}
}
void measurement(){
Measurement measurement;
measurement=bmp180.readValues();
temperature=measurement.temperature;
pressure=measurement.pressure;
}
void tempGraph(){
timerT.attach(&timerTExpired,2);
int j=0; //start graph on left hand side of screen
while(1){
lcd.printString("Menu",0,5);
if (timerTFlag){
timerTFlag=0;
clearCells();
float tempArray[84]; //create array of temperature values
measurement(); //read in the measured values of temperature
tempArray[j]=(temperature/47);
j++; //add one to j so that the next point plotted moves across the screen by one pixel
lcd.plotArray(tempArray); //plot the array
wait(0.1); //wait one second before plotting the next point
}
if (buttonFlag){
buttonFlag=0;
menu();
}
}
}
void pressGraph(){
timerP.attach(&timerPExpired,2);
int j=0;
while(1){
lcd.printString("Menu",0,5);
if (timerPFlag){
timerPFlag=0;
clearCells();
float pressArray[84];
measurement();
pressArray[j]=(pressure/1100);
j++;
lcd.plotArray(pressArray);
wait(0.1);
}
if (buttonFlag){
buttonFlag=0;
menu();
}
}
}
void menu(){
buttonleft.rise(&buttonPressed);
while(1) {
wait (0.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 (buttonFlag){ //left button takes the user to the graph option
buttonFlag=0;
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 (buttonFlag) {
buttonFlag=0;
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 (buttonFlag) {
buttonFlag=0;
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();
}