Ultraschall Test Geschwindigkeitsregelung
Fork of BertlLib by
Bertl14.h@6:78243412d2b3, 2015-03-05 (annotated)
- Committer:
- hollegha2
- Date:
- Thu Mar 05 17:39:16 2015 +0000
- Revision:
- 6:78243412d2b3
- Parent:
- 2:16a5d3302ddb
- Child:
- 7:01d2bc098b6d
FrontButton
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hollegha2 | 0:e0131e671ea0 | 1 | |
hollegha2 | 0:e0131e671ea0 | 2 | #ifndef Bertl14_h |
hollegha2 | 0:e0131e671ea0 | 3 | #define Bertl14_h |
hollegha2 | 0:e0131e671ea0 | 4 | |
hollegha2 | 0:e0131e671ea0 | 5 | class Motor { |
hollegha2 | 0:e0131e671ea0 | 6 | public: |
hollegha2 | 0:e0131e671ea0 | 7 | Motor(PinName pwm, PinName fwd, PinName rev); |
hollegha2 | 0:e0131e671ea0 | 8 | void SetPow(float aPow); |
hollegha2 | 0:e0131e671ea0 | 9 | protected: |
hollegha2 | 0:e0131e671ea0 | 10 | PwmOut _pwm; |
hollegha2 | 0:e0131e671ea0 | 11 | DigitalOut _fwd; |
hollegha2 | 0:e0131e671ea0 | 12 | DigitalOut _rev; |
hollegha2 | 0:e0131e671ea0 | 13 | }; |
hollegha2 | 0:e0131e671ea0 | 14 | |
hollegha2 | 0:e0131e671ea0 | 15 | class BertlDrive : public Motor { |
hollegha2 | 0:e0131e671ea0 | 16 | public: |
hollegha2 | 0:e0131e671ea0 | 17 | int16_t encCnt; |
hollegha2 | 0:e0131e671ea0 | 18 | public: |
hollegha2 | 0:e0131e671ea0 | 19 | BertlDrive(PinName pwm, PinName fwd, PinName rev, PinName encoder); |
hollegha2 | 0:e0131e671ea0 | 20 | void Init(); |
hollegha2 | 0:e0131e671ea0 | 21 | private: |
hollegha2 | 0:e0131e671ea0 | 22 | void EncoderISR(); |
hollegha2 | 0:e0131e671ea0 | 23 | InterruptIn _enc; |
hollegha2 | 0:e0131e671ea0 | 24 | }; |
hollegha2 | 0:e0131e671ea0 | 25 | |
hollegha2 | 0:e0131e671ea0 | 26 | |
hollegha2 | 0:e0131e671ea0 | 27 | const int BTN_FLL = 0x80; |
hollegha2 | 0:e0131e671ea0 | 28 | const int BTN_FL = 0x04; |
hollegha2 | 0:e0131e671ea0 | 29 | const int BTN_FM = 0x01; |
hollegha2 | 0:e0131e671ea0 | 30 | const int BTN_FR = 0x08; |
hollegha2 | 0:e0131e671ea0 | 31 | const int BTN_FRR = 0x40; |
hollegha2 | 0:e0131e671ea0 | 32 | const int BTN_BL = 0x10; |
hollegha2 | 0:e0131e671ea0 | 33 | const int BTN_BM = 0x02; |
hollegha2 | 0:e0131e671ea0 | 34 | const int BTN_BR = 0x20; |
hollegha2 | 0:e0131e671ea0 | 35 | |
hollegha2 | 0:e0131e671ea0 | 36 | const int LED_FL1 = 0x01; // white die vordere |
hollegha2 | 0:e0131e671ea0 | 37 | const int LED_FL2 = 0x02; // red die hintere |
hollegha2 | 0:e0131e671ea0 | 38 | const int LED_FR1 = 0x04; // white |
hollegha2 | 0:e0131e671ea0 | 39 | const int LED_FR2 = 0x08; // red |
hollegha2 | 0:e0131e671ea0 | 40 | const int LED_ALL_FRONT = 0x0F; |
hollegha2 | 0:e0131e671ea0 | 41 | |
hollegha2 | 0:e0131e671ea0 | 42 | const int LED_BL1 = 0x20; // red back left outher |
hollegha2 | 0:e0131e671ea0 | 43 | const int LED_BL2 = 0x10; // red back left inner |
hollegha2 | 0:e0131e671ea0 | 44 | const int LED_BR1 = 0x80; // red back right outher |
hollegha2 | 0:e0131e671ea0 | 45 | const int LED_BR2 = 0x40; // red back right inner |
hollegha2 | 0:e0131e671ea0 | 46 | const int LED_ALL_BACK = 0xF0; |
hollegha2 | 0:e0131e671ea0 | 47 | |
hollegha2 | 0:e0131e671ea0 | 48 | |
hollegha2 | 0:e0131e671ea0 | 49 | class PortEx { |
hollegha2 | 0:e0131e671ea0 | 50 | public: |
hollegha2 | 0:e0131e671ea0 | 51 | // Current State of Buttons is refreshed with ReadButtons() |
hollegha2 | 0:e0131e671ea0 | 52 | int16_t btns; |
hollegha2 | 0:e0131e671ea0 | 53 | uint8_t btnEvent; |
hollegha2 | 0:e0131e671ea0 | 54 | uint8_t useISR; |
hollegha2 | 0:e0131e671ea0 | 55 | public: |
hollegha2 | 0:e0131e671ea0 | 56 | PortEx(); |
hollegha2 | 0:e0131e671ea0 | 57 | void Init(); |
hollegha2 | 0:e0131e671ea0 | 58 | |
hollegha2 | 0:e0131e671ea0 | 59 | void SetLedPort(uint8_t aBitPattern); // NO local Bit-OR |
hollegha2 | 0:e0131e671ea0 | 60 | void SetLeds(uint8_t aBitPattern); |
hollegha2 | 0:e0131e671ea0 | 61 | void ToggleLeds(uint8_t aBitPattern); |
hollegha2 | 0:e0131e671ea0 | 62 | void ClearLeds(); |
hollegha2 | 0:e0131e671ea0 | 63 | |
hollegha2 | 0:e0131e671ea0 | 64 | void ReadButtons(); |
hollegha2 | 0:e0131e671ea0 | 65 | void WaitUntilButtonPressed(); |
hollegha2 | 6:78243412d2b3 | 66 | void WaitUntilFrontButtonPressed(); |
hollegha2 | 0:e0131e671ea0 | 67 | |
hollegha2 | 0:e0131e671ea0 | 68 | bool IsButton(int aBitPattern) |
hollegha2 | 0:e0131e671ea0 | 69 | { return btns & aBitPattern; } |
hollegha2 | 0:e0131e671ea0 | 70 | |
hollegha2 | 0:e0131e671ea0 | 71 | bool IsAnyFrontButton() |
hollegha2 | 0:e0131e671ea0 | 72 | { return btns & (BTN_FL|BTN_FM|BTN_FR); } |
hollegha2 | 0:e0131e671ea0 | 73 | |
hollegha2 | 0:e0131e671ea0 | 74 | bool IsAnyBackButton() |
hollegha2 | 0:e0131e671ea0 | 75 | { return btns & (BTN_BL|BTN_BM|BTN_BR); } |
hollegha2 | 0:e0131e671ea0 | 76 | private: |
hollegha2 | 0:e0131e671ea0 | 77 | uint8_t _currLeds; |
hollegha2 | 0:e0131e671ea0 | 78 | void p6ISR(); |
hollegha2 | 0:e0131e671ea0 | 79 | I2C _i2c; |
hollegha2 | 0:e0131e671ea0 | 80 | const int DEV = 0x40; |
hollegha2 | 0:e0131e671ea0 | 81 | InterruptIn _p6Event; |
hollegha2 | 0:e0131e671ea0 | 82 | }; |
hollegha2 | 0:e0131e671ea0 | 83 | |
hollegha2 | 0:e0131e671ea0 | 84 | |
hollegha2 | 0:e0131e671ea0 | 85 | class UsDistSens { |
hollegha2 | 0:e0131e671ea0 | 86 | public: |
hollegha2 | 0:e0131e671ea0 | 87 | UsDistSens(PinName pinTrigger, PinName pinEcho); |
hollegha2 | 0:e0131e671ea0 | 88 | void StartMeas(); |
hollegha2 | 0:e0131e671ea0 | 89 | private: |
hollegha2 | 0:e0131e671ea0 | 90 | void RisingISR(); |
hollegha2 | 0:e0131e671ea0 | 91 | void FallingISR(); |
hollegha2 | 0:e0131e671ea0 | 92 | private: |
hollegha2 | 0:e0131e671ea0 | 93 | DigitalOut trigger; |
hollegha2 | 0:e0131e671ea0 | 94 | InterruptIn echo; |
hollegha2 | 0:e0131e671ea0 | 95 | Timer stw; |
hollegha2 | 0:e0131e671ea0 | 96 | public: |
hollegha2 | 0:e0131e671ea0 | 97 | int dist; |
hollegha2 | 0:e0131e671ea0 | 98 | float distCM; |
hollegha2 | 0:e0131e671ea0 | 99 | }; |
hollegha2 | 0:e0131e671ea0 | 100 | |
hollegha2 | 2:16a5d3302ddb | 101 | #ifndef ANALOGIN_HL |
hollegha2 | 2:16a5d3302ddb | 102 | #define ANALOGIN_HL |
hollegha2 | 2:16a5d3302ddb | 103 | class AnalogInHL : public AnalogIn { |
hollegha2 | 2:16a5d3302ddb | 104 | public: |
hollegha2 | 2:16a5d3302ddb | 105 | AnalogInHL(PinName pin) : AnalogIn(pin) { } |
hollegha2 | 2:16a5d3302ddb | 106 | int Read() |
hollegha2 | 2:16a5d3302ddb | 107 | { return read_u16()>>6; } |
hollegha2 | 2:16a5d3302ddb | 108 | }; |
hollegha2 | 0:e0131e671ea0 | 109 | #endif |
hollegha2 | 2:16a5d3302ddb | 110 | |
hollegha2 | 2:16a5d3302ddb | 111 | #endif |
hollegha2 | 2:16a5d3302ddb | 112 | |
hollegha2 | 2:16a5d3302ddb | 113 | |
hollegha2 | 2:16a5d3302ddb | 114 | |
hollegha2 | 2:16a5d3302ddb | 115 | |
hollegha2 | 2:16a5d3302ddb | 116 | |
hollegha2 | 2:16a5d3302ddb | 117 | |
hollegha2 | 2:16a5d3302ddb | 118 | |
hollegha2 | 2:16a5d3302ddb | 119 | |
hollegha2 | 2:16a5d3302ddb | 120 | |
hollegha2 | 2:16a5d3302ddb | 121 | |
hollegha2 | 2:16a5d3302ddb | 122 | |
hollegha2 | 2:16a5d3302ddb | 123 | |
hollegha2 | 2:16a5d3302ddb | 124 | |
hollegha2 | 2:16a5d3302ddb | 125 | |
hollegha2 | 2:16a5d3302ddb | 126 | |
hollegha2 | 2:16a5d3302ddb | 127 | |
hollegha2 | 2:16a5d3302ddb | 128 | |
hollegha2 | 2:16a5d3302ddb | 129 | |
hollegha2 | 2:16a5d3302ddb | 130 | |
hollegha2 | 2:16a5d3302ddb | 131 | |
hollegha2 | 2:16a5d3302ddb | 132 | |
hollegha2 | 2:16a5d3302ddb | 133 | |
hollegha2 | 2:16a5d3302ddb | 134 |