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 #include "MPU.h" 00003 #include "HCSR04.h" 00004 #include "TextLCD.h" 00005 00006 /* 00007 class LED_interrupt 00008 { 00009 00010 public: 00011 LED_interrupt(PinName tipkalo_pin, PinName led_pin) : _tipkalo(tipkalo_pin), _stanje(led_pin) 00012 { 00013 _tipkalo.fall(callback(this, &LED_interrupt::promjena)); 00014 off(); 00015 }; 00016 00017 void off(void) 00018 { 00019 _stanje = 1; 00020 }; 00021 00022 void promjena(void) 00023 { 00024 _stanje = !_stanje; 00025 }; 00026 00027 private: 00028 DigitalOut _stanje; 00029 InterruptIn _tipkalo; 00030 00031 }; 00032 */ 00033 DigitalOut led(LED1); 00034 Timer debounce; 00035 00036 void flip() 00037 { 00038 if (debounce.read_ms()>200) 00039 led = !led; 00040 debounce.reset(); 00041 } 00042 00043 Serial pc(USBTX,USBRX); 00044 Senzor mpu(p9,p10); // žiroskop (Sda, Scl) 00045 HCSR04 sensor(p7,p8); // ultrazvučni senzor (trig, echo) 00046 TextLCD lcd(p15, p16, p17, p18, p19, p20, TextLCD::LCD16x2); // display (rs, e, d4-d7) 00047 InterruptIn _tipkalo(p12); 00048 00049 void calc() 00050 { 00051 sensor.startMeasurement(); 00052 } 00053 00054 int main() 00055 { 00056 float angle[3] = {0, 0, 0}; 00057 float temp; 00058 float sampleTime = 0.5; 00059 Ticker ticker; 00060 float distance; 00061 00062 pc.printf("\nPocnimo\n"); 00063 00064 sensor.setRanges(2, 400); 00065 pc.printf("Minimum sensor range = %g cm\n\rMaximum sensor range = %g cm\n\r", sensor.getMinRange(), sensor.getMaxRange()); 00066 ticker.attach(&calc, sampleTime); 00067 00068 //LED_interrupt(p12,LED1); 00069 debounce.start(); 00070 _tipkalo.rise(&flip); 00071 00072 while(true) { 00073 00074 mpu.finalAngle(angle); 00075 temp=mpu.getTemp(); 00076 distance = sensor.getDistance_mm(); 00077 00078 //lcd.cls(); 00079 //lcd.locate(0,1); 00080 pc.printf("\n\rpitch: %.4f", angle[0]); 00081 00082 //lcd.locate(0,0); 00083 pc.printf("\n\rroll: %.4f", angle[1]); 00084 00085 pc.printf("\n\rTemp: %.4f",temp); 00086 pc.printf("\n\rDistance: %f mm\r", distance); 00087 00088 wait(1); 00089 00090 } 00091 }
Generated on Wed Jul 13 2022 08:57:40 by
1.7.2