Applied engineering Team / Mbed 2 deprecated Programski_zadatak_23

Dependencies:   Display1602 mbed nRF24L01P

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "nRF24L01P.h"
00003 #include "Display1602.h"
00004 
00005 I2C MSP430G(p9, p10); //sda, sc1
00006 nRF24L01P odasiljac(p11,p12,p13,p14,p28,p27);  //// mosi, miso, sck, csn, ce, irq
00007 //AnalogIn speed(p15);
00008 //AnalogIn direction(p26);
00009 Display1602 display(p19, p20, p21, p22, p23, p24,p25,p26,p29,p30,p18); 
00010    
00011     
00012 
00013 Serial pc(USBTX, USBRX); //tx, rx
00014 
00015 //void start();
00016 float readTempAndVoltage(int ,int, int , int);
00017 
00018 int main() 
00019 {
00020 
00021 
00022 display.SetXY(0,0);
00023 display.Print("Glupost je ");
00024 display.SetXY(0,1);
00025 display.Print("neunistiva!!!");
00026 
00027 float t,v;
00028 
00029    
00030     
00031     while(1) 
00032     {
00033               
00034         t=readTempAndVoltage(0xC0,0x55,0x94,0);//55
00035         v=readTempAndVoltage(0xC1,0xff,0x94,1);//55
00036         
00037         //v=readTempAndVoltage(0xC1,0x55,0x94,1);
00038         
00039         //v=voltage(0xC1,0x55,0x94) ;   
00040         
00041                
00042         
00043         
00044         display.Clear();
00045         display.SetXY(0,0);
00046         display.printf("Temp = %.2f   C", t); // print on screen
00047         display.SetXY(0,1);
00048         display.printf("Voltage = %.2f V", v); // print on screen//wait(1);
00049         //display.SetXY(0,1);
00050         //display.printf("Voltage = %.1f V", voltage(0xC1,0x55,0x94)); // print on screen
00051         
00052     }
00053 }
00054 
00055 float readTempAndVoltage(int config_b0,int config_b1, int addr, int mode)
00056 {
00057     char config_t[2]; // transmitt buffer
00058     char value_read[2]; // read buffer 
00059     wait(0.1);
00060     
00061     MSP430G.write(addr, config_t, 2);
00062     wait_us(20);
00063     
00064     if (mode==0)
00065         {
00066             float temp;
00067             config_t[0] = config_b0;    //0xC1; //config slave to int temp
00068             config_t[1] = config_b1;    //0x55; // config data byte1, BOut  
00069             MSP430G.read(addr, value_read, 2); //read the two-byte temp data 
00070             temp = value_read[0]+value_read[1]*256;
00071             temp=temp/10.;
00072             return temp;
00073         }
00074     else if(mode==1)
00075         {
00076             float voltage;
00077             config_t[0] = config_b0;    //0xC1; //config slave to int temp
00078             config_t[1] = config_b1;    //0x55; // config data byte1, BOut  
00079             MSP430G.read(addr, value_read, 2); //read the two-byte temp data 
00080             voltage = value_read[0]+value_read[1]*256;
00081             voltage = 1.5 * (voltage / 1023);
00082             return voltage;
00083         }
00084     else
00085         return 0;
00086 
00087 }