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.
Dependents: Gameduino Factory_monitor_0v1 mbed_mindflex NEW_NFC_TEST
Revision 0:8d785e80d3ba, committed 2012-10-21
- Comitter:
- TheChrisyd
- Date:
- Sun Oct 21 14:26:18 2012 +0000
- Child:
- 1:b22cf6a5957d
- Commit message:
- commit for publishing
Changed in this revision
| arduino.c | Show annotated file Show diff for this revision Revisions of this file |
| arduino.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/arduino.c Sun Oct 21 14:26:18 2012 +0000
@@ -0,0 +1,268 @@
+/**
+ * @section LICENSE
+ * Copyright (c) 2012
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * @section DESCRIPTION
+ * This is a library for allowing the use of programs written for the Arduino
+ * with the mbed. This was started for use with the Gameduino shield Library.
+ * It is currently uncomplete and not fully tested, but I don't see myself spending time on it.
+ * See TODOs and check http://arduino.cc/en/Reference/HomePage for missing parts
+ *
+ * @file arduino.c
+ *
+ * Example:
+ * @code
+ *
+ * #include "mbed.h"
+ * #include "arduino.h"
+ *
+ * void setup(){
+ * // setup code
+ * }
+ *
+ *void loop(){
+ * // loop code
+ *}
+ *
+ * int main() {
+ * timer_start();
+ * setup();
+ * while(1) {
+ * loop();
+ * }
+ * }
+ * @endcode
+ */
+ #include "arduino.h"
+
+/*****************************************************
+ Digital I/O
+
+ pinMode()- TODO
+ digitalWrite()- TODO
+ digitalRead()- TODO
+
+******************************************************/
+
+/*****************************************************
+ Analog I/O
+
+ analogReference() - TODO
+ analogRead() - TODO
+ analogWrite()-(PWM) - TODO
+
+*****************************************************/
+
+/*****************************************************
+ Advanced I/O
+
+ tone() - TODO
+ noTone() - TODO
+ shiftOut() - TODO
+ shiftIn() - TODO
+ pulseIn() - TODO
+
+*****************************************************/
+
+/*****************************************************
+ Time
+
+ millis() - need to start timer first
+ micros() - need to start timer first
+ delay() - done by Macro
+ delayMicroseconds() - Done byMacro
+
+*****************************************************/
+
+Timer arduino_timer;
+/** start the arduino_timer timer for millis() and micros() running.
+ *
+ * @param void
+ */
+void timer_start(void) {
+ arduino_timer.start();
+}
+/** return a long for the amount of time since the timer was started in milliseconds.
+ *
+ * @param void
+ */
+long millis(void) {
+ return arduino_timer.read_ms();
+}
+/** return a long for the amount of time since the timer was started in microseconds.
+ *
+ * @param void
+ */
+long micros(void) {
+ return arduino_timer.read_us();
+}
+
+/** Macro for delay()
+ *
+ * @param void
+ */
+#define delay(x) (wait_ms(x))
+/** Macro for delayMicroseconds()
+ *
+ * @param void
+ */
+#define delayMicroseconds(x) (wait_us(x))
+
+/*****************************************************
+ Maths
+
+ min() - done by Macro
+ max() - done by Macro
+ abs() - done by Macro
+ constrain() - TODO
+ map() - TODO
+ pow() - implemented by including math.h
+ sqrt() - implemented by including math.h
+
+*****************************************************/
+
+/** Macro for min()
+ *
+ * @param any
+ */
+#define min(a,b) ((a)<(b)?(a):(b))
+/** Macro for max()
+ *
+ * @param any
+ */
+#define max(a,b) ((a)>(b)?(a):(b))
+/** Macro for abs()
+ *
+ * @param any
+ */
+#define abs(x) ((x)>0?(x):(x*-1))
+
+/*****************************************************
+ Trigonometry
+
+ sin() - implemented by including math.h
+ cos() - implemented by including math.h
+ tan() - implemented by including math.h
+
+*****************************************************/
+
+/*****************************************************
+ Random Numbers
+
+ randomSeed() - done by Macro
+ random() - function below
+
+*****************************************************/
+
+/** Macro for randomSeed()
+ *
+ * @param int
+ */
+#define randomSeed(x) srand(x)
+/** generates a random number from 0 to defined number
+ *
+ * @param number maximum value for random number
+ */
+int random(int number) {
+ return (rand()%number);
+}
+/** generates a random number between two numbers
+ *
+ * @param numberone minimum value for random number
+ * @param numbertwo maximum value for random number
+ */
+int random(int numberone, int numbertwo) {
+ int random = 0;
+ if ((numberone < 0) && (numbertwo < 0)) {
+ numberone = numberone * -1;
+ numbertwo = numbertwo * -1;
+ random = -1 * (rand()%(numberone + numbertwo));
+ }
+ if ((numbertwo < 0) && (numberone >= 0)) {
+ numbertwo = numbertwo * -1;
+ random = (rand()%(numberone + numbertwo)) - numbertwo;
+ }
+ if ((numberone < 0) && (numbertwo >= 0)) {
+ numberone = numberone * -1;
+ random = (rand()%(numberone + numbertwo)) - numberone;
+ } else {
+ random = (rand()%(numberone + numbertwo)) - min(numberone, numbertwo);
+ }
+ return random;
+}
+
+/*****************************************************
+ Bits and Bytes
+
+ lowByte() - function below
+ highByte() - function below
+ bitRead() - TODO
+ bitWrite() - TODO
+ bitSet() - TODO
+ bitClear() - TODO
+ bit() - TODO
+
+*****************************************************/
+
+/** returns the lower nibble of first byte
+ *
+ * @param high byte of which the high nibble is required
+ */
+byte lowByte(short int low) {
+ byte bytelow = 0;
+ bytelow = (low & 0xFF);
+ return bytelow;
+}
+/** returns the higher nibble of first byte
+ *
+ * @param high byte of which the high nibble is required
+ */
+byte highByte(short int high) {
+ byte bytehigh = 0;
+ bytehigh = ((high >> 8) & 0xFF);
+ return bytehigh;
+}
+
+
+
+/*****************************************************
+ External Interrupts
+
+ attachInterrupt() - TODO
+ detachInterrupt() - TODO
+
+*****************************************************/
+
+/*****************************************************
+ Interrupts
+
+ interrupts() - TODO
+ noInterrupts() - TODO
+
+*****************************************************/
+
+/*****************************************************
+ Communication
+
+ Serial - TODO
+ Stream - TODO
+
+*****************************************************/
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/arduino.h Sun Oct 21 14:26:18 2012 +0000 @@ -0,0 +1,67 @@ +/** + * @section LICENSE + * Copyright (c) 2012 Chris Dick + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @section DESCRIPTION + * This is a library for allowing the use of programs written for the Arduino + * with the mbed. This was started for use with the Gameduino shield Library + * + * + */ +#ifndef ARDUINO_H +#define ARDUINO_H + +#include "mbed.h" +#include "math.h" +// Macros + +#define pgm_read_word_near(x) (*(const unsigned int*)x) +#define pgm_read_int_near(x) (*(const int*)x) +#define pgm_read_int(x) (*(const int*)x) +#define pgm_read_byte(x) (*(const char*)x) +#define pgm_read_byte_near(x) (*(const char*)x) +#define PROGMEM const +#define char(x) ((char)x) +#define byte(x) ((byte)x) +#define int(x) ((int)x) +#define word(x) ((word)x) +#define long(x) ((long)x) +#define float(x) ((float)x) +// typedefs + +typedef unsigned char prog_uint8_t; +typedef unsigned int prog_uint16_t; +typedef unsigned char byte; +typedef bool boolean; +typedef unsigned char prog_uchar; +typedef signed char prog_char; +typedef signed long int word; + +// function prototypes + +void timer_start(void); +long millis(void); +long micros(void); +byte lowByte(short int low); +byte highByte(short int high); +int random(int number); +int random(int numberone, int numbertwo); +#endif