Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of arduino by
arduino.cpp
00001 /** 00002 * @section LICENSE 00003 * Copyright (c) 2012 00004 * 00005 * Permission is hereby granted, free of charge, to any person obtaining a copy 00006 * of this software and associated documentation files (the "Software"), to deal 00007 * in the Software without restriction, including without limitation the rights 00008 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00009 * copies of the Software, and to permit persons to whom the Software is 00010 * furnished to do so, subject to the following conditions: 00011 * 00012 * The above copyright notice and this permission notice shall be included in 00013 * all copies or substantial portions of the Software. 00014 * 00015 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00016 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00017 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00018 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00019 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00020 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00021 * THE SOFTWARE. 00022 * 00023 * @section DESCRIPTION 00024 * This is a library for allowing the use of programs written for the Arduino 00025 * with the mbed. This was started for use with the Gameduino shield Library. 00026 * It is currently uncomplete and not fully tested, but I don't see myself spending time on it. 00027 * See TODOs and check http://arduino.cc/en/Reference/HomePage for missing parts 00028 * 00029 * @file arduino.c 00030 * 00031 * Example: 00032 * @code 00033 * 00034 * #include "mbed.h" 00035 * #include "arduino.h" 00036 * 00037 * void setup(){ 00038 * // setup code 00039 * } 00040 * 00041 *void loop(){ 00042 * // loop code 00043 *} 00044 * 00045 * int main() { 00046 * timer_start(); 00047 * setup(); 00048 * while(1) { 00049 * loop(); 00050 * } 00051 * } 00052 * @endcode 00053 */ 00054 #include "Arduino.h" 00055 00056 /***************************************************** 00057 Digital I/O 00058 00059 pinMode()- TODO 00060 digitalWrite()- TODO 00061 digitalRead()- TODO 00062 00063 ******************************************************/ 00064 void *pinMode(PinName pin, uint8_t f) 00065 { 00066 if (f == INPUT) 00067 return new DigitalIn(pin); 00068 else if (f == OUTPUT) 00069 return new DigitalOut(pin); 00070 } 00071 00072 /***************************************************** 00073 Analog I/O 00074 00075 analogReference() - TODO 00076 analogRead() - TODO 00077 analogWrite()-(PWM) - TODO 00078 00079 *****************************************************/ 00080 00081 /***************************************************** 00082 Advanced I/O 00083 00084 tone() - TODO 00085 noTone() - TODO 00086 shiftOut() - TODO 00087 shiftIn() - TODO 00088 pulseIn() - TODO 00089 00090 *****************************************************/ 00091 00092 /***************************************************** 00093 Time 00094 00095 millis() - need to start timer first 00096 micros() - need to start timer first 00097 delay() - done by Macro 00098 delayMicroseconds() - Done byMacro 00099 00100 *****************************************************/ 00101 00102 Timer arduino_timer; 00103 /** start the arduino_timer timer for millis() and micros() running. 00104 * 00105 * @param void 00106 */ 00107 void timer_start(void) { 00108 arduino_timer.start(); 00109 } 00110 /** return a long for the amount of time since the timer was started in milliseconds. 00111 * 00112 * @param void 00113 */ 00114 long millis(void) { 00115 return arduino_timer.read_ms(); 00116 } 00117 /** return a long for the amount of time since the timer was started in microseconds. 00118 * 00119 * @param void 00120 */ 00121 long micros(void) { 00122 return arduino_timer.read_us(); 00123 } 00124 00125 00126 /***************************************************** 00127 Maths 00128 00129 min() - done by Macro 00130 max() - done by Macro 00131 abs() - done by Macro 00132 constrain() - TODO 00133 map() - TODO 00134 pow() - implemented by including math.h 00135 sqrt() - implemented by including math.h 00136 00137 *****************************************************/ 00138 00139 00140 /***************************************************** 00141 Trigonometry 00142 00143 sin() - implemented by including math.h 00144 cos() - implemented by including math.h 00145 tan() - implemented by including math.h 00146 00147 *****************************************************/ 00148 00149 /***************************************************** 00150 Random Numbers 00151 00152 randomSeed() - done by Macro 00153 random() - function below 00154 00155 *****************************************************/ 00156 00157 /** generates a random number from 0 to defined number 00158 * 00159 * @param number maximum value for random number 00160 */ 00161 int random(int number) { 00162 return (rand()%number); 00163 } 00164 /** generates a random number between two numbers 00165 * 00166 * @param numberone minimum value for random number 00167 * @param numbertwo maximum value for random number 00168 */ 00169 int random(int numberone, int numbertwo) { 00170 int random = 0; 00171 if ((numberone < 0) && (numbertwo < 0)) { 00172 numberone = numberone * -1; 00173 numbertwo = numbertwo * -1; 00174 random = -1 * (rand()%(numberone + numbertwo)); 00175 } 00176 if ((numbertwo < 0) && (numberone >= 0)) { 00177 numbertwo = numbertwo * -1; 00178 random = (rand()%(numberone + numbertwo)) - numbertwo; 00179 } 00180 if ((numberone < 0) && (numbertwo >= 0)) { 00181 numberone = numberone * -1; 00182 random = (rand()%(numberone + numbertwo)) - numberone; 00183 } else { 00184 random = (rand()%(numberone + numbertwo)) - min(numberone, numbertwo); 00185 } 00186 return random; 00187 } 00188 00189 /***************************************************** 00190 Bits and Bytes 00191 00192 lowByte() - function below 00193 highByte() - function below 00194 bitRead() - TODO 00195 bitWrite() - TODO 00196 bitSet() - TODO 00197 bitClear() - TODO 00198 bit() - TODO 00199 00200 *****************************************************/ 00201 00202 /** returns the lower nibble of first byte 00203 * 00204 * @param high byte of which the high nibble is required 00205 */ 00206 byte lowByte(short int low) { 00207 byte bytelow = 0; 00208 bytelow = (low & 0xFF); 00209 return bytelow; 00210 } 00211 /** returns the higher nibble of first byte 00212 * 00213 * @param high byte of which the high nibble is required 00214 */ 00215 byte highByte(short int high) { 00216 byte bytehigh = 0; 00217 bytehigh = ((high >> 8) & 0xFF); 00218 return bytehigh; 00219 } 00220 00221 00222 00223 /***************************************************** 00224 External Interrupts 00225 00226 attachInterrupt() - TODO 00227 detachInterrupt() - TODO 00228 00229 *****************************************************/ 00230 00231 /***************************************************** 00232 Interrupts 00233 00234 interrupts() - TODO 00235 noInterrupts() - TODO 00236 00237 *****************************************************/ 00238 00239 /***************************************************** 00240 Communication 00241 00242 Serial - TODO 00243 Stream - TODO 00244 00245 *****************************************************/
Generated on Sun Aug 14 2022 23:40:23 by
1.7.2
