Isme LDR ya Pot ka value print hotai, l ye p type karne pe. Kuch aur type kia to kuch nai hotai.

Dependencies:   mbed

Committer:
akashlal
Date:
Fri Jul 01 09:24:41 2016 +0000
Revision:
0:d5eb245951cf
na

Who changed what in which revision?

UserRevisionLine numberNew contents of line
akashlal 0:d5eb245951cf 1 #include "mbed.h"
akashlal 0:d5eb245951cf 2
akashlal 0:d5eb245951cf 3 Serial pc(USBTX,USBRX);
akashlal 0:d5eb245951cf 4 AnalogIn pot(PTB0);
akashlal 0:d5eb245951cf 5 AnalogIn ldr(PTB1);
akashlal 0:d5eb245951cf 6 float potf; //Declaring float value for Potentiometer reading
akashlal 0:d5eb245951cf 7 int poti; //Declaring int value for Potentiometer reading
akashlal 0:d5eb245951cf 8 float ldrf; //Declaring float value for LDR reading
akashlal 0:d5eb245951cf 9 int ldri; //Declaring Integer value for LDR reading
akashlal 0:d5eb245951cf 10 char i;
akashlal 0:d5eb245951cf 11
akashlal 0:d5eb245951cf 12 int main()
akashlal 0:d5eb245951cf 13 {
akashlal 0:d5eb245951cf 14 while(1)
akashlal 0:d5eb245951cf 15 {
akashlal 0:d5eb245951cf 16 if(pc.readable())
akashlal 0:d5eb245951cf 17 {
akashlal 0:d5eb245951cf 18 i=pc.getc();
akashlal 0:d5eb245951cf 19 if(i=='l')
akashlal 0:d5eb245951cf 20 {
akashlal 0:d5eb245951cf 21 ldrf=ldr.read();
akashlal 0:d5eb245951cf 22 ldri=ldrf*1000;
akashlal 0:d5eb245951cf 23 pc.printf("LDR value is %d \n\r",ldri);
akashlal 0:d5eb245951cf 24 }
akashlal 0:d5eb245951cf 25 if(i=='p')
akashlal 0:d5eb245951cf 26 {
akashlal 0:d5eb245951cf 27 potf=pot.read();
akashlal 0:d5eb245951cf 28 poti=potf*3.3*1000;
akashlal 0:d5eb245951cf 29 pc.printf("Pot value is %d \n\r",poti);
akashlal 0:d5eb245951cf 30 }
akashlal 0:d5eb245951cf 31 }
akashlal 0:d5eb245951cf 32 wait(0.5);
akashlal 0:d5eb245951cf 33 }
akashlal 0:d5eb245951cf 34 }