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.
main.cpp
00001 #include "mbed.h" 00002 //master-transmitter i master-receiver 00003 00004 I2C i2c_master(PB_3, PB_10); //sda, scl ADRESE!!!!!!!!!!! 00005 Serial pc(USBTX, USBRX); 00006 PwmOut motor(PB_4); //fan 00007 00008 const int addr_senzor = 0x90; //adresa senzora 00009 const int addr_slave = 0x80; //adresa slave mbed-a 00010 float temp; 00011 float temp_ref; 00012 char podaci[2]; 00013 char config_t[3]; //config polje 00014 char temp_read[2]; //polje za 16 bita podataka sa senzora 00015 00016 void config_senzor(){ 00017 config_t[0]=0x01; 00018 config_t[1]=0x60; 00019 config_t[2]=0xA0; 00020 i2c_master.write(addr_senzor, config_t, 3); 00021 config_t[0]=0x00; 00022 } 00023 00024 float ocitaj_temp(){ 00025 i2c_master.read(addr_senzor, temp_read, 2); // ocitanje s TMP102 senzora 00026 temp = 0.0625 * (((temp_read[0] << 8) + temp_read[1]) >> 4); //konverzija u float vrijednost deg C 00027 pc.printf("Poslana T: %2f\n\r", temp); 00028 //float temp_k = temp + 273.15; 00029 //float temp_f = (temp*(9/5)) + 32; 00030 return temp; 00031 } 00032 00033 void salji_temp(){ 00034 //master-transmitter 00035 i2c_master.write(addr_slave<<1, temp_read, 2, false); 00036 pc.printf("Poslani podaci:%x,%x\n\r", podaci[0], podaci[1]); 00037 wait_us(50); 00038 } 00039 00040 //void upali_motor(){ 00041 // motor.period_us(50); 00042 // motor.pulsewidth_us(30); 00043 // } 00044 00045 float dohvati_ref(){ 00046 //master-receiver 00047 i2c_master.read(addr_slave<<1, podaci, 2); 00048 pc.printf("Primljeni podaci:%x,%x\n\r", podaci[0], podaci[1]); 00049 wait_us(50); 00050 float ref = (podaci[0]<<8) + podaci[1]; 00051 temp_ref = (float)ref/100; 00052 pc.printf("Primljena T_ref: %f\n\r", temp_ref); 00053 return temp_ref; 00054 } 00055 00056 //void usporedi_temp(){ 00057 // if (temp_ref < temp){ 00058 // upali_motor(); 00059 // }else{ 00060 // motor = 0; 00061 // } 00062 // } 00063 00064 00065 int main(){ 00066 //char podaci[3] = {0x25, 0xAB, 0x11}; 00067 //char config_t[3]; //config polje 00068 //char temp_read[2]; //polje za 16 bita podataka sa senzora 00069 //const int addr_senzor = 0x90; //adresa senzora 00070 //const int addr_slave = 0x80; //adresa slave mbed-a 00071 00072 motor = 0; 00073 config_senzor(); 00074 i2c_master.frequency(100000); //100kHz 00075 00076 while(1){ 00077 ocitaj_temp(); 00078 dohvati_ref(); 00079 //usporedi_temp(); 00080 //if (temp_ref < temp){ 00081 // motor.period_us(50); 00082 // motor.pulsewidth_us(30); 00083 // }else{ 00084 // motor = 0; 00085 // } 00086 salji_temp(); 00087 //prihvati_mod(); //treba napraviti funkciju kojom ce se birati mod c, k, f 00088 00089 00090 //master-transmitter 00091 //i2c_master.write(addr_slave<<1, temp_read, 2, false); 00092 //pc.printf("Poslani podaci:%x,%x,\n", podaci[0], podaci[1]); 00093 //wait_us(50); 00094 00095 //master-reicever 00096 //i2c_master.read(addr_slave<<1, podaci, 2, false); 00097 //pc.printf("Primljeni podaci:%x,%x\n", podaci[0], podaci[1]); 00098 00099 wait(0.5); 00100 00101 } 00102 }
Generated on Thu Aug 11 2022 07:34:32 by
1.7.2