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 Oct 02 01:09:55 2013 +0000
Revision:
1:200aad416161
Parent:
0:da22b0b4395a
mbed robotracer for education.
;

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_I2C_SLAVE_H
hayama 0:da22b0b4395a 17 #define MBED_I2C_SLAVE_H
hayama 0:da22b0b4395a 18
hayama 0:da22b0b4395a 19 #include "platform.h"
hayama 0:da22b0b4395a 20
hayama 0:da22b0b4395a 21 #if DEVICE_I2CSLAVE
hayama 0:da22b0b4395a 22
hayama 0:da22b0b4395a 23 #include "i2c_api.h"
hayama 0:da22b0b4395a 24
hayama 0:da22b0b4395a 25 namespace mbed {
hayama 0:da22b0b4395a 26
hayama 0:da22b0b4395a 27 /** An I2C Slave, used for communicating with an I2C Master device
hayama 0:da22b0b4395a 28 *
hayama 0:da22b0b4395a 29 * Example:
hayama 0:da22b0b4395a 30 * @code
hayama 0:da22b0b4395a 31 * // Simple I2C responder
hayama 0:da22b0b4395a 32 * #include <mbed.h>
hayama 0:da22b0b4395a 33 *
hayama 0:da22b0b4395a 34 * I2CSlave slave(p9, p10);
hayama 0:da22b0b4395a 35 *
hayama 0:da22b0b4395a 36 * int main() {
hayama 0:da22b0b4395a 37 * char buf[10];
hayama 0:da22b0b4395a 38 * char msg[] = "Slave!";
hayama 0:da22b0b4395a 39 *
hayama 0:da22b0b4395a 40 * slave.address(0xA0);
hayama 0:da22b0b4395a 41 * while (1) {
hayama 0:da22b0b4395a 42 * int i = slave.receive();
hayama 0:da22b0b4395a 43 * switch (i) {
hayama 0:da22b0b4395a 44 * case I2CSlave::ReadAddressed:
hayama 0:da22b0b4395a 45 * slave.write(msg, strlen(msg) + 1); // Includes null char
hayama 0:da22b0b4395a 46 * break;
hayama 0:da22b0b4395a 47 * case I2CSlave::WriteGeneral:
hayama 0:da22b0b4395a 48 * slave.read(buf, 10);
hayama 0:da22b0b4395a 49 * printf("Read G: %s\n", buf);
hayama 0:da22b0b4395a 50 * break;
hayama 0:da22b0b4395a 51 * case I2CSlave::WriteAddressed:
hayama 0:da22b0b4395a 52 * slave.read(buf, 10);
hayama 0:da22b0b4395a 53 * printf("Read A: %s\n", buf);
hayama 0:da22b0b4395a 54 * break;
hayama 0:da22b0b4395a 55 * }
hayama 0:da22b0b4395a 56 * for(int i = 0; i < 10; i++) buf[i] = 0; // Clear buffer
hayama 0:da22b0b4395a 57 * }
hayama 0:da22b0b4395a 58 * }
hayama 0:da22b0b4395a 59 * @endcode
hayama 0:da22b0b4395a 60 */
hayama 0:da22b0b4395a 61 class I2CSlave {
hayama 0:da22b0b4395a 62
hayama 0:da22b0b4395a 63 public:
hayama 0:da22b0b4395a 64 enum RxStatus {
hayama 0:da22b0b4395a 65 NoData = 0,
hayama 0:da22b0b4395a 66 ReadAddressed = 1,
hayama 0:da22b0b4395a 67 WriteGeneral = 2,
hayama 0:da22b0b4395a 68 WriteAddressed = 3
hayama 0:da22b0b4395a 69 };
hayama 0:da22b0b4395a 70
hayama 0:da22b0b4395a 71 /** Create an I2C Slave interface, connected to the specified pins.
hayama 0:da22b0b4395a 72 *
hayama 0:da22b0b4395a 73 * @param sda I2C data line pin
hayama 0:da22b0b4395a 74 * @param scl I2C clock line pin
hayama 0:da22b0b4395a 75 */
hayama 0:da22b0b4395a 76 I2CSlave(PinName sda, PinName scl);
hayama 0:da22b0b4395a 77
hayama 0:da22b0b4395a 78 /** Set the frequency of the I2C interface
hayama 0:da22b0b4395a 79 *
hayama 0:da22b0b4395a 80 * @param hz The bus frequency in hertz
hayama 0:da22b0b4395a 81 */
hayama 0:da22b0b4395a 82 void frequency(int hz);
hayama 0:da22b0b4395a 83
hayama 0:da22b0b4395a 84 /** Checks to see if this I2C Slave has been addressed.
hayama 0:da22b0b4395a 85 *
hayama 0:da22b0b4395a 86 * @returns
hayama 0:da22b0b4395a 87 * A status indicating if the device has been addressed, and how
hayama 0:da22b0b4395a 88 * - NoData - the slave has not been addressed
hayama 0:da22b0b4395a 89 * - ReadAddressed - the master has requested a read from this slave
hayama 0:da22b0b4395a 90 * - WriteAddressed - the master is writing to this slave
hayama 0:da22b0b4395a 91 * - WriteGeneral - the master is writing to all slave
hayama 0:da22b0b4395a 92 */
hayama 0:da22b0b4395a 93 int receive(void);
hayama 0:da22b0b4395a 94
hayama 0:da22b0b4395a 95 /** Read from an I2C master.
hayama 0:da22b0b4395a 96 *
hayama 0:da22b0b4395a 97 * @param data pointer to the byte array to read data in to
hayama 0:da22b0b4395a 98 * @param length maximum number of bytes to read
hayama 0:da22b0b4395a 99 *
hayama 0:da22b0b4395a 100 * @returns
hayama 0:da22b0b4395a 101 * 0 on success,
hayama 0:da22b0b4395a 102 * non-0 otherwise
hayama 0:da22b0b4395a 103 */
hayama 0:da22b0b4395a 104 int read(char *data, int length);
hayama 0:da22b0b4395a 105
hayama 0:da22b0b4395a 106 /** Read a single byte from an I2C master.
hayama 0:da22b0b4395a 107 *
hayama 0:da22b0b4395a 108 * @returns
hayama 0:da22b0b4395a 109 * the byte read
hayama 0:da22b0b4395a 110 */
hayama 0:da22b0b4395a 111 int read(void);
hayama 0:da22b0b4395a 112
hayama 0:da22b0b4395a 113 /** Write to an I2C master.
hayama 0:da22b0b4395a 114 *
hayama 0:da22b0b4395a 115 * @param data pointer to the byte array to be transmitted
hayama 0:da22b0b4395a 116 * @param length the number of bytes to transmite
hayama 0:da22b0b4395a 117 *
hayama 0:da22b0b4395a 118 * @returns
hayama 0:da22b0b4395a 119 * 0 on success,
hayama 0:da22b0b4395a 120 * non-0 otherwise
hayama 0:da22b0b4395a 121 */
hayama 0:da22b0b4395a 122 int write(const char *data, int length);
hayama 0:da22b0b4395a 123
hayama 0:da22b0b4395a 124 /** Write a single byte to an I2C master.
hayama 0:da22b0b4395a 125 *
hayama 0:da22b0b4395a 126 * @data the byte to write
hayama 0:da22b0b4395a 127 *
hayama 0:da22b0b4395a 128 * @returns
hayama 0:da22b0b4395a 129 * '1' if an ACK was received,
hayama 0:da22b0b4395a 130 * '0' otherwise
hayama 0:da22b0b4395a 131 */
hayama 0:da22b0b4395a 132 int write(int data);
hayama 0:da22b0b4395a 133
hayama 0:da22b0b4395a 134 /** Sets the I2C slave address.
hayama 0:da22b0b4395a 135 *
hayama 0:da22b0b4395a 136 * @param address The address to set for the slave (ignoring the least
hayama 0:da22b0b4395a 137 * signifcant bit). If set to 0, the slave will only respond to the
hayama 0:da22b0b4395a 138 * general call address.
hayama 0:da22b0b4395a 139 */
hayama 0:da22b0b4395a 140 void address(int address);
hayama 0:da22b0b4395a 141
hayama 0:da22b0b4395a 142 /** Reset the I2C slave back into the known ready receiving state.
hayama 0:da22b0b4395a 143 */
hayama 0:da22b0b4395a 144 void stop(void);
hayama 0:da22b0b4395a 145
hayama 0:da22b0b4395a 146 protected:
hayama 0:da22b0b4395a 147 i2c_t _i2c;
hayama 0:da22b0b4395a 148 };
hayama 0:da22b0b4395a 149
hayama 0:da22b0b4395a 150 } // namespace mbed
hayama 0:da22b0b4395a 151
hayama 0:da22b0b4395a 152 #endif
hayama 0:da22b0b4395a 153
hayama 0:da22b0b4395a 154 #endif