mbed robotracer for education.

Robotracer (line follower robot ) using stepper motor.

/media/uploads/hayama/cimg8463.jpg

/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

Committer:
hayama
Date:
Wed Jun 19 10:00:41 2013 +0000
Revision:
0:da22b0b4395a
mbed robotracer for education ver 1.0

Who changed what in which revision?

UserRevisionLine numberNew 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_PWMOUT_H
hayama 0:da22b0b4395a 17 #define MBED_PWMOUT_H
hayama 0:da22b0b4395a 18
hayama 0:da22b0b4395a 19 #include "platform.h"
hayama 0:da22b0b4395a 20
hayama 0:da22b0b4395a 21 #if DEVICE_PWMOUT
hayama 0:da22b0b4395a 22 #include "pwmout_api.h"
hayama 0:da22b0b4395a 23
hayama 0:da22b0b4395a 24 namespace mbed {
hayama 0:da22b0b4395a 25
hayama 0:da22b0b4395a 26 /** A pulse-width modulation digital output
hayama 0:da22b0b4395a 27 *
hayama 0:da22b0b4395a 28 * Example
hayama 0:da22b0b4395a 29 * @code
hayama 0:da22b0b4395a 30 * // Fade a led on.
hayama 0:da22b0b4395a 31 * #include "mbed.h"
hayama 0:da22b0b4395a 32 *
hayama 0:da22b0b4395a 33 * PwmOut led(LED1);
hayama 0:da22b0b4395a 34 *
hayama 0:da22b0b4395a 35 * int main() {
hayama 0:da22b0b4395a 36 * while(1) {
hayama 0:da22b0b4395a 37 * led = led + 0.01;
hayama 0:da22b0b4395a 38 * wait(0.2);
hayama 0:da22b0b4395a 39 * if(led == 1.0) {
hayama 0:da22b0b4395a 40 * led = 0;
hayama 0:da22b0b4395a 41 * }
hayama 0:da22b0b4395a 42 * }
hayama 0:da22b0b4395a 43 * }
hayama 0:da22b0b4395a 44 * @endcode
hayama 0:da22b0b4395a 45 *
hayama 0:da22b0b4395a 46 * @note
hayama 0:da22b0b4395a 47 * On the LPC1768 and LPC2368, the PWMs all share the same
hayama 0:da22b0b4395a 48 * period - if you change the period for one, you change it for all.
hayama 0:da22b0b4395a 49 * Although routines that change the period maintain the duty cycle
hayama 0:da22b0b4395a 50 * for its PWM, all other PWMs will require their duty cycle to be
hayama 0:da22b0b4395a 51 * refreshed.
hayama 0:da22b0b4395a 52 */
hayama 0:da22b0b4395a 53 class PwmOut {
hayama 0:da22b0b4395a 54
hayama 0:da22b0b4395a 55 public:
hayama 0:da22b0b4395a 56
hayama 0:da22b0b4395a 57 /** Create a PwmOut connected to the specified pin
hayama 0:da22b0b4395a 58 *
hayama 0:da22b0b4395a 59 * @param pin PwmOut pin to connect to
hayama 0:da22b0b4395a 60 */
hayama 0:da22b0b4395a 61 PwmOut(PinName pin) {
hayama 0:da22b0b4395a 62 pwmout_init(&_pwm, pin);
hayama 0:da22b0b4395a 63 }
hayama 0:da22b0b4395a 64
hayama 0:da22b0b4395a 65 /** Set the ouput duty-cycle, specified as a percentage (float)
hayama 0:da22b0b4395a 66 *
hayama 0:da22b0b4395a 67 * @param value A floating-point value representing the output duty-cycle,
hayama 0:da22b0b4395a 68 * specified as a percentage. The value should lie between
hayama 0:da22b0b4395a 69 * 0.0f (representing on 0%) and 1.0f (representing on 100%).
hayama 0:da22b0b4395a 70 * Values outside this range will be saturated to 0.0f or 1.0f.
hayama 0:da22b0b4395a 71 */
hayama 0:da22b0b4395a 72 void write(float value) {
hayama 0:da22b0b4395a 73 pwmout_write(&_pwm, value);
hayama 0:da22b0b4395a 74 }
hayama 0:da22b0b4395a 75
hayama 0:da22b0b4395a 76 /** Return the current output duty-cycle setting, measured as a percentage (float)
hayama 0:da22b0b4395a 77 *
hayama 0:da22b0b4395a 78 * @returns
hayama 0:da22b0b4395a 79 * A floating-point value representing the current duty-cycle being output on the pin,
hayama 0:da22b0b4395a 80 * measured as a percentage. The returned value will lie between
hayama 0:da22b0b4395a 81 * 0.0f (representing on 0%) and 1.0f (representing on 100%).
hayama 0:da22b0b4395a 82 *
hayama 0:da22b0b4395a 83 * @note
hayama 0:da22b0b4395a 84 * This value may not match exactly the value set by a previous <write>.
hayama 0:da22b0b4395a 85 */
hayama 0:da22b0b4395a 86 float read() {
hayama 0:da22b0b4395a 87 return pwmout_read(&_pwm);
hayama 0:da22b0b4395a 88 }
hayama 0:da22b0b4395a 89
hayama 0:da22b0b4395a 90 /** Set the PWM period, specified in seconds (float), keeping the duty cycle the same.
hayama 0:da22b0b4395a 91 *
hayama 0:da22b0b4395a 92 * @note
hayama 0:da22b0b4395a 93 * The resolution is currently in microseconds; periods smaller than this
hayama 0:da22b0b4395a 94 * will be set to zero.
hayama 0:da22b0b4395a 95 */
hayama 0:da22b0b4395a 96 void period(float seconds) {
hayama 0:da22b0b4395a 97 pwmout_period(&_pwm, seconds);
hayama 0:da22b0b4395a 98 }
hayama 0:da22b0b4395a 99
hayama 0:da22b0b4395a 100 /** Set the PWM period, specified in milli-seconds (int), keeping the duty cycle the same.
hayama 0:da22b0b4395a 101 */
hayama 0:da22b0b4395a 102 void period_ms(int ms) {
hayama 0:da22b0b4395a 103 pwmout_period_ms(&_pwm, ms);
hayama 0:da22b0b4395a 104 }
hayama 0:da22b0b4395a 105
hayama 0:da22b0b4395a 106 /** Set the PWM period, specified in micro-seconds (int), keeping the duty cycle the same.
hayama 0:da22b0b4395a 107 */
hayama 0:da22b0b4395a 108 void period_us(int us) {
hayama 0:da22b0b4395a 109 pwmout_period_us(&_pwm, us);
hayama 0:da22b0b4395a 110 }
hayama 0:da22b0b4395a 111
hayama 0:da22b0b4395a 112 /** Set the PWM pulsewidth, specified in seconds (float), keeping the period the same.
hayama 0:da22b0b4395a 113 */
hayama 0:da22b0b4395a 114 void pulsewidth(float seconds) {
hayama 0:da22b0b4395a 115 pwmout_pulsewidth(&_pwm, seconds);
hayama 0:da22b0b4395a 116 }
hayama 0:da22b0b4395a 117
hayama 0:da22b0b4395a 118 /** Set the PWM pulsewidth, specified in milli-seconds (int), keeping the period the same.
hayama 0:da22b0b4395a 119 */
hayama 0:da22b0b4395a 120 void pulsewidth_ms(int ms) {
hayama 0:da22b0b4395a 121 pwmout_pulsewidth_ms(&_pwm, ms);
hayama 0:da22b0b4395a 122 }
hayama 0:da22b0b4395a 123
hayama 0:da22b0b4395a 124 /** Set the PWM pulsewidth, specified in micro-seconds (int), keeping the period the same.
hayama 0:da22b0b4395a 125 */
hayama 0:da22b0b4395a 126 void pulsewidth_us(int us) {
hayama 0:da22b0b4395a 127 pwmout_pulsewidth_us(&_pwm, us);
hayama 0:da22b0b4395a 128 }
hayama 0:da22b0b4395a 129
hayama 0:da22b0b4395a 130 #ifdef MBED_OPERATORS
hayama 0:da22b0b4395a 131 /** A operator shorthand for write()
hayama 0:da22b0b4395a 132 */
hayama 0:da22b0b4395a 133 PwmOut& operator= (float value) {
hayama 0:da22b0b4395a 134 write(value);
hayama 0:da22b0b4395a 135 return *this;
hayama 0:da22b0b4395a 136 }
hayama 0:da22b0b4395a 137
hayama 0:da22b0b4395a 138 PwmOut& operator= (PwmOut& rhs) {
hayama 0:da22b0b4395a 139 write(rhs.read());
hayama 0:da22b0b4395a 140 return *this;
hayama 0:da22b0b4395a 141 }
hayama 0:da22b0b4395a 142
hayama 0:da22b0b4395a 143 /** An operator shorthand for read()
hayama 0:da22b0b4395a 144 */
hayama 0:da22b0b4395a 145 operator float() {
hayama 0:da22b0b4395a 146 return read();
hayama 0:da22b0b4395a 147 }
hayama 0:da22b0b4395a 148 #endif
hayama 0:da22b0b4395a 149
hayama 0:da22b0b4395a 150 protected:
hayama 0:da22b0b4395a 151 pwmout_t _pwm;
hayama 0:da22b0b4395a 152 };
hayama 0:da22b0b4395a 153
hayama 0:da22b0b4395a 154 } // namespace mbed
hayama 0:da22b0b4395a 155
hayama 0:da22b0b4395a 156 #endif
hayama 0:da22b0b4395a 157
hayama 0:da22b0b4395a 158 #endif