Programski_zadatak_23

Dependencies:   Display1602 mbed nRF24L01P

Revision:
1:3213ce6cd7e1
Parent:
0:e67a9248e8f8
Child:
2:698c8f9140e6
diff -r e67a9248e8f8 -r 3213ce6cd7e1 main.cpp
--- a/main.cpp	Thu Jan 21 16:21:55 2016 +0000
+++ b/main.cpp	Sat Jan 23 18:06:49 2016 +0000
@@ -1,12 +1,87 @@
 #include "mbed.h"
+#include "Display1602.h"
+//#include "nRF24L01P.h"
+I2C MSP430G(p9, p10); //sda, sc1
+//nRF24L01P odasiljac(p11,p12,p13,p14,p28,p27); 
+//AnalogIn speed(p15);
+//AnalogIn direction(p26);
+Display1602 display(p19, p20, p21, p22, p23, p24,p25,p26,p29,p30,p18); 
+   
+    
 
-DigitalOut myled(LED1);
+Serial pc(USBTX, USBRX); //tx, rx
+
+//void start();
+float temp(int ,int, int );
+float voltage(int ,int , int);
+
+
+
+
+int main() 
+{
+
 
-int main() {
-    while(1) {
-        myled = 1;
-        wait(0.2);
-        myled = 0;
-        wait(0.2);
+display.SetXY(0,0);
+display.Print("Glupost je ");
+display.SetXY(0,1);
+display.Print("neunistiva!!!");
+
+float t,v;
+
+   
+    
+    while(1) 
+    {
+        wait(1);        
+        t=temp(0xC0,0x55,0x94);
+        wait(1);
+        //v=voltage(0xC1,0x55,0x94) ;   
+        
+               
+        
+        
+        display.Clear();
+        display.SetXY(0,0);
+        display.printf("Temp = %.1f degC", t); // print on screen
+        //display.SetXY(0,1);
+        //display.printf("Voltage = %.1f V", v); // print on screen//wait(1);
+        //display.SetXY(0,1);
+        //display.printf("Voltage = %.1f V", voltage(0xC1,0x55,0x94)); // print on screen
+        
     }
 }
+
+float temp(int config_t0,int config_t1, int addr)
+{
+    float temp;
+    char config_t[2]; // transmitt buffer
+    char temp_read[2]; // read buffer 
+    config_t[0] = config_t0;    //0xC1; //config slave to int temp
+    config_t[1] = config_t1;    //0x55; // config data byte1, BOut 
+    
+    MSP430G.write(addr, config_t, 2);
+    wait_us(20);
+    
+    MSP430G.read(addr, temp_read, 2); //read the two-byte temp data            
+    temp = temp_read[0]+temp_read[1]*256;
+    temp=temp/10;
+    return temp;
+}  
+
+float voltage(int config_v0,int config_v1, int addr)
+{
+    float volts;
+    char config_v[2]; // transmitt buffer
+    char volt_read[2]; // read buffer 
+    config_v[0] = config_v0;    //0xC1; //config slave to int temp
+    config_v[1] = config_v1;    //0x55; // config data byte1, BOut 
+    
+    MSP430G.write(addr, config_v, 2);
+    wait_us(20);
+    
+    MSP430G.read(addr, volt_read, 2); //read the two-byte temp data            
+    volts = volt_read[0]+volt_read[1]*256;
+    
+    return volts;
+}