mbed robotracer for education.
Robotracer (line follower robot ) using stepper motor.
/media/uploads/hayama/mbedrobotracer-manual-english.pdf
/media/uploads/hayama/mbedrobotracer-manual-japanese.pdf
/media/uploads/hayama/eagle-design-robotracer.zip
movie -> https://www.youtube.com/watch?v=INwun8gSds4
(for competition->) https://www.youtube.com/watch?v=l_gP2pUt4w0
mbed/InterruptIn.h@1:200aad416161, 2013-10-02 (annotated)
- Committer:
- hayama
- Date:
- Wed Oct 02 01:09:55 2013 +0000
- Revision:
- 1:200aad416161
- Parent:
- 0:da22b0b4395a
mbed robotracer for education.
;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hayama | 0:da22b0b4395a | 1 | /* mbed Microcontroller Library |
hayama | 0:da22b0b4395a | 2 | * Copyright (c) 2006-2013 ARM Limited |
hayama | 0:da22b0b4395a | 3 | * |
hayama | 0:da22b0b4395a | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
hayama | 0:da22b0b4395a | 5 | * you may not use this file except in compliance with the License. |
hayama | 0:da22b0b4395a | 6 | * You may obtain a copy of the License at |
hayama | 0:da22b0b4395a | 7 | * |
hayama | 0:da22b0b4395a | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
hayama | 0:da22b0b4395a | 9 | * |
hayama | 0:da22b0b4395a | 10 | * Unless required by applicable law or agreed to in writing, software |
hayama | 0:da22b0b4395a | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
hayama | 0:da22b0b4395a | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
hayama | 0:da22b0b4395a | 13 | * See the License for the specific language governing permissions and |
hayama | 0:da22b0b4395a | 14 | * limitations under the License. |
hayama | 0:da22b0b4395a | 15 | */ |
hayama | 0:da22b0b4395a | 16 | #ifndef MBED_INTERRUPTIN_H |
hayama | 0:da22b0b4395a | 17 | #define MBED_INTERRUPTIN_H |
hayama | 0:da22b0b4395a | 18 | |
hayama | 0:da22b0b4395a | 19 | #include "platform.h" |
hayama | 0:da22b0b4395a | 20 | |
hayama | 0:da22b0b4395a | 21 | #if DEVICE_INTERRUPTIN |
hayama | 0:da22b0b4395a | 22 | |
hayama | 0:da22b0b4395a | 23 | #include "gpio_api.h" |
hayama | 0:da22b0b4395a | 24 | #include "gpio_irq_api.h" |
hayama | 0:da22b0b4395a | 25 | |
hayama | 0:da22b0b4395a | 26 | #include "FunctionPointer.h" |
hayama | 0:da22b0b4395a | 27 | |
hayama | 0:da22b0b4395a | 28 | namespace mbed { |
hayama | 0:da22b0b4395a | 29 | |
hayama | 0:da22b0b4395a | 30 | /** A digital interrupt input, used to call a function on a rising or falling edge |
hayama | 0:da22b0b4395a | 31 | * |
hayama | 0:da22b0b4395a | 32 | * Example: |
hayama | 0:da22b0b4395a | 33 | * @code |
hayama | 0:da22b0b4395a | 34 | * // Flash an LED while waiting for events |
hayama | 0:da22b0b4395a | 35 | * |
hayama | 0:da22b0b4395a | 36 | * #include "mbed.h" |
hayama | 0:da22b0b4395a | 37 | * |
hayama | 0:da22b0b4395a | 38 | * InterruptIn event(p16); |
hayama | 0:da22b0b4395a | 39 | * DigitalOut led(LED1); |
hayama | 0:da22b0b4395a | 40 | * |
hayama | 0:da22b0b4395a | 41 | * void trigger() { |
hayama | 0:da22b0b4395a | 42 | * printf("triggered!\n"); |
hayama | 0:da22b0b4395a | 43 | * } |
hayama | 0:da22b0b4395a | 44 | * |
hayama | 0:da22b0b4395a | 45 | * int main() { |
hayama | 0:da22b0b4395a | 46 | * event.rise(&trigger); |
hayama | 0:da22b0b4395a | 47 | * while(1) { |
hayama | 0:da22b0b4395a | 48 | * led = !led; |
hayama | 0:da22b0b4395a | 49 | * wait(0.25); |
hayama | 0:da22b0b4395a | 50 | * } |
hayama | 0:da22b0b4395a | 51 | * } |
hayama | 0:da22b0b4395a | 52 | * @endcode |
hayama | 0:da22b0b4395a | 53 | */ |
hayama | 0:da22b0b4395a | 54 | class InterruptIn { |
hayama | 0:da22b0b4395a | 55 | |
hayama | 0:da22b0b4395a | 56 | public: |
hayama | 0:da22b0b4395a | 57 | |
hayama | 0:da22b0b4395a | 58 | /** Create an InterruptIn connected to the specified pin |
hayama | 0:da22b0b4395a | 59 | * |
hayama | 0:da22b0b4395a | 60 | * @param pin InterruptIn pin to connect to |
hayama | 0:da22b0b4395a | 61 | * @param name (optional) A string to identify the object |
hayama | 0:da22b0b4395a | 62 | */ |
hayama | 0:da22b0b4395a | 63 | InterruptIn(PinName pin); |
hayama | 0:da22b0b4395a | 64 | virtual ~InterruptIn(); |
hayama | 0:da22b0b4395a | 65 | |
hayama | 0:da22b0b4395a | 66 | int read(); |
hayama | 0:da22b0b4395a | 67 | #ifdef MBED_OPERATORS |
hayama | 0:da22b0b4395a | 68 | operator int(); |
hayama | 0:da22b0b4395a | 69 | |
hayama | 0:da22b0b4395a | 70 | #endif |
hayama | 0:da22b0b4395a | 71 | |
hayama | 0:da22b0b4395a | 72 | /** Attach a function to call when a rising edge occurs on the input |
hayama | 0:da22b0b4395a | 73 | * |
hayama | 0:da22b0b4395a | 74 | * @param fptr A pointer to a void function, or 0 to set as none |
hayama | 0:da22b0b4395a | 75 | */ |
hayama | 0:da22b0b4395a | 76 | void rise(void (*fptr)(void)); |
hayama | 0:da22b0b4395a | 77 | |
hayama | 0:da22b0b4395a | 78 | /** Attach a member function to call when a rising edge occurs on the input |
hayama | 0:da22b0b4395a | 79 | * |
hayama | 0:da22b0b4395a | 80 | * @param tptr pointer to the object to call the member function on |
hayama | 0:da22b0b4395a | 81 | * @param mptr pointer to the member function to be called |
hayama | 0:da22b0b4395a | 82 | */ |
hayama | 0:da22b0b4395a | 83 | template<typename T> |
hayama | 0:da22b0b4395a | 84 | void rise(T* tptr, void (T::*mptr)(void)) { |
hayama | 0:da22b0b4395a | 85 | _rise.attach(tptr, mptr); |
hayama | 0:da22b0b4395a | 86 | gpio_irq_set(&gpio_irq, IRQ_RISE, 1); |
hayama | 0:da22b0b4395a | 87 | } |
hayama | 0:da22b0b4395a | 88 | |
hayama | 0:da22b0b4395a | 89 | /** Attach a function to call when a falling edge occurs on the input |
hayama | 0:da22b0b4395a | 90 | * |
hayama | 0:da22b0b4395a | 91 | * @param fptr A pointer to a void function, or 0 to set as none |
hayama | 0:da22b0b4395a | 92 | */ |
hayama | 0:da22b0b4395a | 93 | void fall(void (*fptr)(void)); |
hayama | 0:da22b0b4395a | 94 | |
hayama | 0:da22b0b4395a | 95 | /** Attach a member function to call when a falling edge occurs on the input |
hayama | 0:da22b0b4395a | 96 | * |
hayama | 0:da22b0b4395a | 97 | * @param tptr pointer to the object to call the member function on |
hayama | 0:da22b0b4395a | 98 | * @param mptr pointer to the member function to be called |
hayama | 0:da22b0b4395a | 99 | */ |
hayama | 0:da22b0b4395a | 100 | template<typename T> |
hayama | 0:da22b0b4395a | 101 | void fall(T* tptr, void (T::*mptr)(void)) { |
hayama | 0:da22b0b4395a | 102 | _fall.attach(tptr, mptr); |
hayama | 0:da22b0b4395a | 103 | gpio_irq_set(&gpio_irq, IRQ_FALL, 1); |
hayama | 0:da22b0b4395a | 104 | } |
hayama | 0:da22b0b4395a | 105 | |
hayama | 0:da22b0b4395a | 106 | /** Set the input pin mode |
hayama | 0:da22b0b4395a | 107 | * |
hayama | 0:da22b0b4395a | 108 | * @param mode PullUp, PullDown, PullNone |
hayama | 0:da22b0b4395a | 109 | */ |
hayama | 0:da22b0b4395a | 110 | void mode(PinMode pull); |
hayama | 0:da22b0b4395a | 111 | |
hayama | 0:da22b0b4395a | 112 | static void _irq_handler(uint32_t id, gpio_irq_event event); |
hayama | 0:da22b0b4395a | 113 | |
hayama | 0:da22b0b4395a | 114 | protected: |
hayama | 0:da22b0b4395a | 115 | gpio_t gpio; |
hayama | 0:da22b0b4395a | 116 | gpio_irq_t gpio_irq; |
hayama | 0:da22b0b4395a | 117 | |
hayama | 0:da22b0b4395a | 118 | FunctionPointer _rise; |
hayama | 0:da22b0b4395a | 119 | FunctionPointer _fall; |
hayama | 0:da22b0b4395a | 120 | }; |
hayama | 0:da22b0b4395a | 121 | |
hayama | 0:da22b0b4395a | 122 | } // namespace mbed |
hayama | 0:da22b0b4395a | 123 | |
hayama | 0:da22b0b4395a | 124 | #endif |
hayama | 0:da22b0b4395a | 125 | |
hayama | 0:da22b0b4395a | 126 | #endif |