Gabriel Smakaj
/
Test
Smakaj
main.cpp@1:3edc991805bd, 2018-11-29 (annotated)
- Committer:
- gabs089
- Date:
- Thu Nov 29 18:39:24 2018 +0000
- Revision:
- 1:3edc991805bd
- Parent:
- 0:cc2bde387551
new version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gabs089 | 0:cc2bde387551 | 1 | #include "mbed.h" |
gabs089 | 1:3edc991805bd | 2 | #include "C12832.h" |
gabs089 | 1:3edc991805bd | 3 | |
gabs089 | 1:3edc991805bd | 4 | |
gabs089 | 1:3edc991805bd | 5 | // Led |
gabs089 | 1:3edc991805bd | 6 | BusOut LEDS(LED1,LED2,LED3,LED4); |
gabs089 | 1:3edc991805bd | 7 | |
gabs089 | 1:3edc991805bd | 8 | // Joystick |
gabs089 | 1:3edc991805bd | 9 | InterruptIn center(p14); |
gabs089 | 1:3edc991805bd | 10 | |
gabs089 | 1:3edc991805bd | 11 | class IsA : public BusOut |
gabs089 | 1:3edc991805bd | 12 | { |
gabs089 | 1:3edc991805bd | 13 | void LedOff(); |
gabs089 | 1:3edc991805bd | 14 | void LedOn(); |
gabs089 | 1:3edc991805bd | 15 | void LedOn(int HexOut); |
gabs089 | 1:3edc991805bd | 16 | void Ein(); |
gabs089 | 1:3edc991805bd | 17 | void Aus(); |
gabs089 | 1:3edc991805bd | 18 | }; |
gabs089 | 1:3edc991805bd | 19 | |
gabs089 | 1:3edc991805bd | 20 | |
gabs089 | 1:3edc991805bd | 21 | void LedOn() |
gabs089 | 1:3edc991805bd | 22 | { |
gabs089 | 1:3edc991805bd | 23 | LEDS = 1; |
gabs089 | 1:3edc991805bd | 24 | } |
gabs089 | 1:3edc991805bd | 25 | |
gabs089 | 1:3edc991805bd | 26 | void LedOff() |
gabs089 | 1:3edc991805bd | 27 | { |
gabs089 | 1:3edc991805bd | 28 | LEDS = 0; |
gabs089 | 1:3edc991805bd | 29 | } |
gabs089 | 1:3edc991805bd | 30 | |
gabs089 | 1:3edc991805bd | 31 | void Ein() |
gabs089 | 1:3edc991805bd | 32 | { |
gabs089 | 1:3edc991805bd | 33 | while(1) |
gabs089 | 1:3edc991805bd | 34 | { |
gabs089 | 1:3edc991805bd | 35 | LEDS = 3; |
gabs089 | 1:3edc991805bd | 36 | { |
gabs089 | 1:3edc991805bd | 37 | return; |
gabs089 | 1:3edc991805bd | 38 | } |
gabs089 | 1:3edc991805bd | 39 | } |
gabs089 | 1:3edc991805bd | 40 | } |
gabs089 | 1:3edc991805bd | 41 | |
gabs089 | 1:3edc991805bd | 42 | void Aus() |
gabs089 | 1:3edc991805bd | 43 | { |
gabs089 | 1:3edc991805bd | 44 | |
gabs089 | 1:3edc991805bd | 45 | } |
gabs089 | 1:3edc991805bd | 46 | |
gabs089 | 0:cc2bde387551 | 47 | class IsAnEvent : public InterruptIn { |
gabs089 | 0:cc2bde387551 | 48 | volatile int16_t _pressed; |
gabs089 | 0:cc2bde387551 | 49 | void _RisingISR(); |
gabs089 | 0:cc2bde387551 | 50 | public: |
gabs089 | 1:3edc991805bd | 51 | IsAnEvent() : InterruptIn(p14) {}; |
gabs089 | 0:cc2bde387551 | 52 | IsAnEvent(PinName pin) : InterruptIn(pin) { |
gabs089 | 0:cc2bde387551 | 53 | rise(callback(this, &IsAnEvent::_RisingISR)); |
gabs089 | 0:cc2bde387551 | 54 | _pressed=0; |
gabs089 | 0:cc2bde387551 | 55 | }; |
gabs089 | 0:cc2bde387551 | 56 | int CheckFlag(); |
gabs089 | 0:cc2bde387551 | 57 | void InitIsr(); |
gabs089 | 0:cc2bde387551 | 58 | }; |
gabs089 | 0:cc2bde387551 | 59 | |
gabs089 | 0:cc2bde387551 | 60 | void IsAnEvent::InitIsr() { |
gabs089 | 0:cc2bde387551 | 61 | rise(callback(this, &IsAnEvent::_RisingISR)); |
gabs089 | 0:cc2bde387551 | 62 | } |
gabs089 | 0:cc2bde387551 | 63 | |
gabs089 | 0:cc2bde387551 | 64 | void IsAnEvent::_RisingISR() { |
gabs089 | 1:3edc991805bd | 65 | wait_ms(500); |
gabs089 | 0:cc2bde387551 | 66 | if( read() ) |
gabs089 | 0:cc2bde387551 | 67 | _pressed = true; |
gabs089 | 0:cc2bde387551 | 68 | } |
gabs089 | 0:cc2bde387551 | 69 | int IsAnEvent::CheckFlag() { |
gabs089 | 0:cc2bde387551 | 70 | if( _pressed ) { |
gabs089 | 0:cc2bde387551 | 71 | _pressed = false; |
gabs089 | 0:cc2bde387551 | 72 | return 1; |
gabs089 | 0:cc2bde387551 | 73 | } |
gabs089 | 0:cc2bde387551 | 74 | return 0; |
gabs089 | 1:3edc991805bd | 75 | |
gabs089 | 1:3edc991805bd | 76 | } |
gabs089 | 1:3edc991805bd | 77 | |
gabs089 | 1:3edc991805bd | 78 | int main() |
gabs089 | 1:3edc991805bd | 79 | { |
gabs089 | 1:3edc991805bd | 80 | LedOn(); |
gabs089 | 1:3edc991805bd | 81 | wait_ms(500); |
gabs089 | 1:3edc991805bd | 82 | LedOff(); |
gabs089 | 1:3edc991805bd | 83 | Ein(); |
gabs089 | 0:cc2bde387551 | 84 | } |