Josip Papratović
/
1_MIKROUPRAVLJACI
Programsko rješenje za uređaj koji mjeri nagib i udaljenost.
Revision 1:024485d1c677, committed 2019-11-16
- Comitter:
- jpapratov
- Date:
- Sat Nov 16 13:15:11 2019 +0000
- Parent:
- 0:34c1f05d8d2c
- Commit message:
- uC
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sat Nov 16 10:14:58 2019 +0000 +++ b/main.cpp Sat Nov 16 13:15:11 2019 +0000 @@ -3,36 +3,48 @@ #include "HCSR04.h" #include "TextLCD.h" +/* class LED_interrupt { - public: - LED_interrupt(PinName tipkalo_pin, PinName led_pin) : _stanje(tipkalo_pin), _tipkalo(led_pin) - { - _tipkalo.fall(callback(this, &LED_interrupt::promjena)); - off(); - }; - - void off(void) - { - _stanje = 0; - }; - - void promjena(void) - { - _stanje = !_stanje; - }; - - private: - DigitalOut _stanje; - InterruptIn _tipkalo; +public: + LED_interrupt(PinName tipkalo_pin, PinName led_pin) : _tipkalo(tipkalo_pin), _stanje(led_pin) + { + _tipkalo.fall(callback(this, &LED_interrupt::promjena)); + off(); + }; + + void off(void) + { + _stanje = 1; + }; + + void promjena(void) + { + _stanje = !_stanje; + }; + +private: + DigitalOut _stanje; + InterruptIn _tipkalo; + }; +*/ +DigitalOut led(LED1); +Timer debounce; +void flip() +{ + if (debounce.read_ms()>200) + led = !led; + debounce.reset(); +} Serial pc(USBTX,USBRX); Senzor mpu(p9,p10); // žiroskop (Sda, Scl) HCSR04 sensor(p7,p8); // ultrazvučni senzor (trig, echo) TextLCD lcd(p15, p16, p17, p18, p19, p20, TextLCD::LCD16x2); // display (rs, e, d4-d7) +InterruptIn _tipkalo(p12); void calc() { @@ -53,9 +65,11 @@ pc.printf("Minimum sensor range = %g cm\n\rMaximum sensor range = %g cm\n\r", sensor.getMinRange(), sensor.getMaxRange()); ticker.attach(&calc, sampleTime); - while(true) { + //LED_interrupt(p12,LED1); + debounce.start(); + _tipkalo.rise(&flip); - LED_interrupt(p15,p16); + while(true) { mpu.finalAngle(angle); temp=mpu.getTemp(); @@ -63,13 +77,13 @@ //lcd.cls(); //lcd.locate(0,1); - pc.printf("\npitch: %.4f", angle[0]); + pc.printf("\n\rpitch: %.4f", angle[0]); //lcd.locate(0,0); - pc.printf("\nroll: %.4f", angle[1]); + pc.printf("\n\rroll: %.4f", angle[1]); - pc.printf("\nTemp: %.4f",temp); - pc.printf("\nDistance: %f mm\r", distance); + pc.printf("\n\rTemp: %.4f",temp); + pc.printf("\n\rDistance: %f mm\r", distance); wait(1);