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.
Dependencies: Projekt TextLCD mbed uStep
main.cpp
00001 #include "mbed.h" 00002 #include "uStep.h" 00003 #include "TextLCD.h" 00004 #include "Projekt.h" 00005 #define THERMISTORNOMINAL 100000 00006 #define TEMPERATURENOMINAL 25 00007 #define BCOEFFICIENT 3950 00008 #define SERIESRESISTOR 10000 00009 TextLCD lcd(PTE0, PTE1, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7 00010 Ticker ticki; 00011 AnalogIn Thermistor(A5); 00012 DigitalIn in0(PTB0); 00013 DigitalIn in1(PTB1); 00014 DigitalIn in2(PTB2); 00015 DigitalIn in3(PTD7); 00016 DigitalIn buttondown(PTE30); 00017 DigitalIn buttonup(PTC2); 00018 DigitalOut andrijinkriz1(PTE29); 00019 DigitalOut andrijinkriz2(PTE23); 00020 00021 uStep motor(PTB8, PTB9,PTB10, PTB11); 00022 00023 float get_temperature() 00024 { 00025 float temperature, resistance; 00026 float steinhart; 00027 int a; 00028 00029 a = Thermistor.read_u16(); // Read 16bit Analog value 00030 00031 00032 /* Calculate the resistance of the thermistor from analog votage read. */ 00033 resistance = (float) SERIESRESISTOR / ((65536.0 / a) - 1); 00034 steinhart = resistance / THERMISTORNOMINAL; // (R/Ro) 00035 steinhart = log(steinhart); // ln(R/Ro) 00036 steinhart /= BCOEFFICIENT; // 1/B * ln(R/Ro) 00037 steinhart += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To) 00038 steinhart = 1.0 / steinhart; // Invert 00039 temperature = steinhart - 273.15; // convert to C 00040 00041 return temperature; 00042 } 00043 00044 00045 00046 void task1(void) 00047 { 00048 andrijinkriz1=!andrijinkriz1; 00049 andrijinkriz2=!andrijinkriz1; 00050 } 00051 00052 00053 float step_brzina = 0.002; 00054 00055 int numstep = 512 ; 00056 00057 int main() 00058 { 00059 Projekt rasvjeta (D9,D8,D2,A3); 00060 while (1) { 00061 if(buttondown==0 && !motor.isRunning()) { 00062 ticki.attach(&task1,0.5); 00063 motor.step(numstep/4,0,step_brzina); 00064 00065 00066 } 00067 if(buttonup==0 && !motor.isRunning()) { 00068 00069 motor.step(numstep/4,1,step_brzina); 00070 ticki.detach(); 00071 andrijinkriz1=0; 00072 andrijinkriz2=0; 00073 00074 } 00075 00076 float value0,value1,value2,value3; 00077 00078 value0 = in0; 00079 value1 = in1; 00080 value2 = in2; 00081 value3 = in3; 00082 00083 00084 if(value0==1) { 00085 lcd.cls(); 00086 lcd.printf("OPREZ SKLISKA CESTA\n"); 00087 } 00088 if(value1==1) { 00089 lcd.cls(); 00090 lcd.printf("NESRECA USPORITE\n"); 00091 } 00092 if(value2==1) { 00093 lcd.cls(); 00094 lcd.printf("DRZITE RAZMAK KEEP DISTANCE \n"); 00095 00096 } 00097 if(value3==1) { 00098 lcd.cls(); 00099 lcd.printf("RADOVI NA CESTI \n"); 00100 00101 } 00102 if(value0==0&&value1==0&&value2==0&&value3==0) { 00103 lcd.cls(); 00104 00105 lcd.printf(" %.1f *C",get_temperature()); 00106 } 00107 00108 00109 } 00110 00111 }
Generated on Sun Jul 24 2022 03:29:39 by
1.7.2