naveen
Dependencies: GPS TextLCD mbed
Fork of AnalogIn-HelloWorld by
main.cpp
- Committer:
- sathguru
- Date:
- 2015-04-19
- Revision:
- 2:f1a2f4029bd6
- Parent:
- 0:101a12a915c6
File content as of revision 2:f1a2f4029bd6:
/* mbed Example Program * Copyright (c) 2006-2014 ARM Limited * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "mbed.h" // Initialize a pins to perform analog input and digital output fucntions AnalogIn ph(A0); AnalogIn CuAm(A1); AnalogIn Na(A2); AnalogIn Cutemp(A3); AnalogIn Disoxy(A4); AnalogIn flu(A5); Serial uart(p28, p27); //Pin 28 TX, pin 27 RX. char a; DigitalOut dout(LED1); #include "TextLCD.h" DigitalOut myled(LED1); DigitalOut myled1(LED2); DigitalOut myled2(LED3); DigitalOut myled3(LED4); TextLCD lcd(p26, p25, p24, p23, p22, p21); // rs, e, d4-d7 float ph1,Am,Ni1,temp,Do,Sod,fl; float CuAm1; void send_ph(unsigned int s) { unsigned int a; unsigned char b,c,d,e,f; a=s/10; b=s%10; c=a%10; d=a/10; e=d%10; f=d/10; putchar(f+0x30); putchar(e+0x30); putchar(c+0x30); putchar(b+0x30); putchar(0x0A); } float map(float x, float in_min, float in_max, float out_min, float out_max) { return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; } int main(void) { lcd.locate(0,0); lcd.printf(" Sensor \n"); lcd.locate(0,1); lcd.printf(" Monitoring1 \n"); wait(1); myled = 1; myled1=1; myled3=1; myled2=1; wait(0.5); myled = 0; myled = 0; myled1=0; myled3=0; myled2=0; wait(0.5); lcd.cls(); while (1) { // test the voltage on the initialized analog pin // and if greater than 0.3 * VCC set the digital pin // to a logic 1 otherwise a logic 0 //if(ain > 0.3f) { // dout = 1; //} else { // dout = 0; // }/ // print the percentage and 16 bit normalized values //lcd.printf(" Temperature \n"); ////////////////////////////////ph///////////////////////////////// lcd.locate(0,0); ph1=ph.read()*100; ph1=map(ph1,0,100,0,14); lcd.printf("PH:%2.0f",ph1); lcd.locate(0,0); lcd.locate(6,0); Am=CuAm.read()*100; Am=map(Am,0,100,0.05,0); if(Am<0.02) { lcd.printf("A:%2.3f", Am); } else { Am=0; lcd.printf("A:%2.3f", Am); } ///////////////// lcd.locate(0,1); Sod=Na.read()*100; Sod=map(Sod,0,100,0,1); if(Sod<0.75) { lcd.printf("S:%2.1f", Sod); } else { Sod=0; lcd.printf("S:%2.1f", Sod); } ////////////////////////ni/////////////////////// Do=Disoxy.read()*100; Do=map(Do,0,200,0,1); printf("%2.0f", Do); /////////////////////////////////////// lcd.locate(5,1); temp=Cutemp.read()*100; temp=map(temp,0,100,0,300); lcd.printf(" T:%2.0f", temp); fl=flu.read()*100; fl=map(fl,0,100,0,2); if(fl<0.46) { lcd.locate(13,0); lcd.printf("Flu"); lcd.locate(11,1); lcd.printf("%2.2f", fl); } else { fl=0; lcd.locate(13,0); lcd.printf("Flu"); lcd.locate(11,1); lcd.printf(" %2.2f", fl); } a=uart.getc(); if (a=='A') { uart.printf("%2.1f", ph1); uart.printf("\n"); } else if (a=='B') { uart.printf("%2.3f", Am); uart.printf("\n"); } ///////////////////////////////////////////////////////////////// else if (a=='C') { uart.printf("%2.1f", Sod); uart.printf("\n"); } else if (a=='D') { uart.printf("%2.0f",temp ); uart.printf("\n"); } else if (a=='E') { uart.printf("%2.0f",Do ); uart.printf("\n"); } else if (a=='F') { uart.printf("%2.2f",fl ); uart.printf("\n"); } } }