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/DigitalOut.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_DIGITALOUT_H |
hayama | 0:da22b0b4395a | 17 | #define MBED_DIGITALOUT_H |
hayama | 0:da22b0b4395a | 18 | |
hayama | 0:da22b0b4395a | 19 | #include "platform.h" |
hayama | 0:da22b0b4395a | 20 | #include "gpio_api.h" |
hayama | 0:da22b0b4395a | 21 | |
hayama | 0:da22b0b4395a | 22 | namespace mbed { |
hayama | 0:da22b0b4395a | 23 | |
hayama | 0:da22b0b4395a | 24 | /** A digital output, used for setting the state of a pin |
hayama | 0:da22b0b4395a | 25 | * |
hayama | 0:da22b0b4395a | 26 | * Example: |
hayama | 0:da22b0b4395a | 27 | * @code |
hayama | 0:da22b0b4395a | 28 | * // Toggle a LED |
hayama | 0:da22b0b4395a | 29 | * #include "mbed.h" |
hayama | 0:da22b0b4395a | 30 | * |
hayama | 0:da22b0b4395a | 31 | * DigitalOut led(LED1); |
hayama | 0:da22b0b4395a | 32 | * |
hayama | 0:da22b0b4395a | 33 | * int main() { |
hayama | 0:da22b0b4395a | 34 | * while(1) { |
hayama | 0:da22b0b4395a | 35 | * led = !led; |
hayama | 0:da22b0b4395a | 36 | * wait(0.2); |
hayama | 0:da22b0b4395a | 37 | * } |
hayama | 0:da22b0b4395a | 38 | * } |
hayama | 0:da22b0b4395a | 39 | * @endcode |
hayama | 0:da22b0b4395a | 40 | */ |
hayama | 0:da22b0b4395a | 41 | class DigitalOut { |
hayama | 0:da22b0b4395a | 42 | |
hayama | 0:da22b0b4395a | 43 | public: |
hayama | 0:da22b0b4395a | 44 | /** Create a DigitalOut connected to the specified pin |
hayama | 0:da22b0b4395a | 45 | * |
hayama | 0:da22b0b4395a | 46 | * @param pin DigitalOut pin to connect to |
hayama | 0:da22b0b4395a | 47 | */ |
hayama | 0:da22b0b4395a | 48 | DigitalOut(PinName pin) { |
hayama | 0:da22b0b4395a | 49 | gpio_init(&gpio, pin, PIN_OUTPUT); |
hayama | 0:da22b0b4395a | 50 | } |
hayama | 0:da22b0b4395a | 51 | |
hayama | 0:da22b0b4395a | 52 | /** Set the output, specified as 0 or 1 (int) |
hayama | 0:da22b0b4395a | 53 | * |
hayama | 0:da22b0b4395a | 54 | * @param value An integer specifying the pin output value, |
hayama | 0:da22b0b4395a | 55 | * 0 for logical 0, 1 (or any other non-zero value) for logical 1 |
hayama | 0:da22b0b4395a | 56 | */ |
hayama | 0:da22b0b4395a | 57 | void write(int value) { |
hayama | 0:da22b0b4395a | 58 | gpio_write(&gpio, value); |
hayama | 0:da22b0b4395a | 59 | } |
hayama | 0:da22b0b4395a | 60 | |
hayama | 0:da22b0b4395a | 61 | /** Return the output setting, represented as 0 or 1 (int) |
hayama | 0:da22b0b4395a | 62 | * |
hayama | 0:da22b0b4395a | 63 | * @returns |
hayama | 0:da22b0b4395a | 64 | * an integer representing the output setting of the pin, |
hayama | 0:da22b0b4395a | 65 | * 0 for logical 0, 1 for logical 1 |
hayama | 0:da22b0b4395a | 66 | */ |
hayama | 0:da22b0b4395a | 67 | int read() { |
hayama | 0:da22b0b4395a | 68 | return gpio_read(&gpio); |
hayama | 0:da22b0b4395a | 69 | } |
hayama | 0:da22b0b4395a | 70 | |
hayama | 0:da22b0b4395a | 71 | #ifdef MBED_OPERATORS |
hayama | 0:da22b0b4395a | 72 | /** A shorthand for write() |
hayama | 0:da22b0b4395a | 73 | */ |
hayama | 0:da22b0b4395a | 74 | DigitalOut& operator= (int value) { |
hayama | 0:da22b0b4395a | 75 | write(value); |
hayama | 0:da22b0b4395a | 76 | return *this; |
hayama | 0:da22b0b4395a | 77 | } |
hayama | 0:da22b0b4395a | 78 | |
hayama | 0:da22b0b4395a | 79 | DigitalOut& operator= (DigitalOut& rhs) { |
hayama | 0:da22b0b4395a | 80 | write(rhs.read()); |
hayama | 0:da22b0b4395a | 81 | return *this; |
hayama | 0:da22b0b4395a | 82 | } |
hayama | 0:da22b0b4395a | 83 | |
hayama | 0:da22b0b4395a | 84 | /** A shorthand for read() |
hayama | 0:da22b0b4395a | 85 | */ |
hayama | 0:da22b0b4395a | 86 | operator int() { |
hayama | 0:da22b0b4395a | 87 | return read(); |
hayama | 0:da22b0b4395a | 88 | } |
hayama | 0:da22b0b4395a | 89 | #endif |
hayama | 0:da22b0b4395a | 90 | |
hayama | 0:da22b0b4395a | 91 | protected: |
hayama | 0:da22b0b4395a | 92 | gpio_t gpio; |
hayama | 0:da22b0b4395a | 93 | }; |
hayama | 0:da22b0b4395a | 94 | |
hayama | 0:da22b0b4395a | 95 | } // namespace mbed |
hayama | 0:da22b0b4395a | 96 | |
hayama | 0:da22b0b4395a | 97 | #endif |