arduino library for mbed

Dependents:   Gameduino2 MemoryGame arduino2

Committer:
aluqard
Date:
Fri Apr 11 07:21:59 2014 +0000
Revision:
0:3b83fc30bbdf
Initial release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
aluqard 0:3b83fc30bbdf 1 #ifndef _ARDUINO_H_
aluqard 0:3b83fc30bbdf 2 #define _ARDUINO_H_
aluqard 0:3b83fc30bbdf 3
aluqard 0:3b83fc30bbdf 4 #include "mbed.h"
aluqard 0:3b83fc30bbdf 5 #include "math.h"
aluqard 0:3b83fc30bbdf 6 // Macros
aluqard 0:3b83fc30bbdf 7
aluqard 0:3b83fc30bbdf 8 #define PI 3.1415926535897932384626433832795
aluqard 0:3b83fc30bbdf 9 #define HALF_PI 1.5707963267948966192313216916398
aluqard 0:3b83fc30bbdf 10 #define TWO_PI 6.283185307179586476925286766559
aluqard 0:3b83fc30bbdf 11 #define DEG_TO_RAD 0.017453292519943295769236907684886
aluqard 0:3b83fc30bbdf 12 #define RAD_TO_DEG 57.295779513082320876798154814105
aluqard 0:3b83fc30bbdf 13
aluqard 0:3b83fc30bbdf 14 #define radians(deg) ((deg)*DEG_TO_RAD)
aluqard 0:3b83fc30bbdf 15 #define degrees(rad) ((rad)*RAD_TO_DEG)
aluqard 0:3b83fc30bbdf 16 #define sq(x) ((x)*(x))
aluqard 0:3b83fc30bbdf 17
aluqard 0:3b83fc30bbdf 18 #define pgm_read_word(x) (*(const short int*)x)
aluqard 0:3b83fc30bbdf 19 #define pgm_read_dword_near(x) (*(const int*)x)
aluqard 0:3b83fc30bbdf 20 #define pgm_read_word_near(x) (*(const unsigned int*)x)
aluqard 0:3b83fc30bbdf 21 #define pgm_read_int_near(x) (*(const int*)x)
aluqard 0:3b83fc30bbdf 22 #define pgm_read_int(x) (*(const int*)x)
aluqard 0:3b83fc30bbdf 23 #define pgm_read_byte(x) (*(const char*)x)
aluqard 0:3b83fc30bbdf 24 #define pgm_read_byte_near(x) (*(const char*)x)
aluqard 0:3b83fc30bbdf 25 #define PROGMEM const
aluqard 0:3b83fc30bbdf 26 #define char(x) ((char)x)
aluqard 0:3b83fc30bbdf 27 #define byte(x) ((byte)x)
aluqard 0:3b83fc30bbdf 28 #define int(x) ((int)x)
aluqard 0:3b83fc30bbdf 29 #define word(x) ((word)x)
aluqard 0:3b83fc30bbdf 30 #define long(x) ((long)x)
aluqard 0:3b83fc30bbdf 31 #define float(x) ((float)x)
aluqard 0:3b83fc30bbdf 32
aluqard 0:3b83fc30bbdf 33 #define in_range(c, lo, up) ((uint8_t)c >= lo && (uint8_t)c <= up)
aluqard 0:3b83fc30bbdf 34 #define isprint(c) in_range(c, 0x20, 0x7f)
aluqard 0:3b83fc30bbdf 35 #define isdigit(c) in_range(c, '0', '9')
aluqard 0:3b83fc30bbdf 36 #define isxdigit(c) (isdigit(c) || in_range(c, 'a', 'f') || in_range(c, 'A', 'F'))
aluqard 0:3b83fc30bbdf 37 #define islower(c) in_range(c, 'a', 'z')
aluqard 0:3b83fc30bbdf 38 #define isspace(c) (c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v')
aluqard 0:3b83fc30bbdf 39
aluqard 0:3b83fc30bbdf 40 /** Macro for delay()
aluqard 0:3b83fc30bbdf 41 *
aluqard 0:3b83fc30bbdf 42 * @param void
aluqard 0:3b83fc30bbdf 43 */
aluqard 0:3b83fc30bbdf 44 #define delay(x) (wait_ms(x))
aluqard 0:3b83fc30bbdf 45 /** Macro for delayMicroseconds()
aluqard 0:3b83fc30bbdf 46 *
aluqard 0:3b83fc30bbdf 47 * @param void
aluqard 0:3b83fc30bbdf 48 */
aluqard 0:3b83fc30bbdf 49 #define delayMicroseconds(x) (wait_us(x))
aluqard 0:3b83fc30bbdf 50
aluqard 0:3b83fc30bbdf 51 /** Macro for min()
aluqard 0:3b83fc30bbdf 52 *
aluqard 0:3b83fc30bbdf 53 * @param any
aluqard 0:3b83fc30bbdf 54 */
aluqard 0:3b83fc30bbdf 55 #define min(a,b) ((a)<(b)?(a):(b))
aluqard 0:3b83fc30bbdf 56 /** Macro for max()
aluqard 0:3b83fc30bbdf 57 *
aluqard 0:3b83fc30bbdf 58 * @param any
aluqard 0:3b83fc30bbdf 59 */
aluqard 0:3b83fc30bbdf 60 #define max(a,b) ((a)>(b)?(a):(b))
aluqard 0:3b83fc30bbdf 61 /** Macro for abs()
aluqard 0:3b83fc30bbdf 62 *
aluqard 0:3b83fc30bbdf 63 * @param any
aluqard 0:3b83fc30bbdf 64 */
aluqard 0:3b83fc30bbdf 65 #define abs(x) ((x)>0?(x):(x*-1))
aluqard 0:3b83fc30bbdf 66
aluqard 0:3b83fc30bbdf 67 /** Macro for randomSeed()
aluqard 0:3b83fc30bbdf 68 *
aluqard 0:3b83fc30bbdf 69 * @param int
aluqard 0:3b83fc30bbdf 70 */
aluqard 0:3b83fc30bbdf 71 #define randomSeed(x) srand(x)
aluqard 0:3b83fc30bbdf 72
aluqard 0:3b83fc30bbdf 73 #define bitRead(value, bit) (((value) >> (bit)) & 0x01)
aluqard 0:3b83fc30bbdf 74 #define bitSet(value, bit) ((value) |= (1UL << (bit)))
aluqard 0:3b83fc30bbdf 75 #define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
aluqard 0:3b83fc30bbdf 76 #define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
aluqard 0:3b83fc30bbdf 77
aluqard 0:3b83fc30bbdf 78 // typedefs
aluqard 0:3b83fc30bbdf 79
aluqard 0:3b83fc30bbdf 80 typedef unsigned char prog_uchar;
aluqard 0:3b83fc30bbdf 81 typedef unsigned char prog_uint8_t;
aluqard 0:3b83fc30bbdf 82 typedef unsigned int prog_uint16_t;
aluqard 0:3b83fc30bbdf 83 typedef unsigned int prog_uint32_t;
aluqard 0:3b83fc30bbdf 84 typedef unsigned char byte;
aluqard 0:3b83fc30bbdf 85 typedef bool boolean;
aluqard 0:3b83fc30bbdf 86 typedef unsigned char prog_uchar;
aluqard 0:3b83fc30bbdf 87 typedef signed char prog_char;
aluqard 0:3b83fc30bbdf 88 typedef signed long int word;
aluqard 0:3b83fc30bbdf 89
aluqard 0:3b83fc30bbdf 90 // function prototypes
aluqard 0:3b83fc30bbdf 91
aluqard 0:3b83fc30bbdf 92 void timer_start(void);
aluqard 0:3b83fc30bbdf 93 long millis(void);
aluqard 0:3b83fc30bbdf 94 long micros(void);
aluqard 0:3b83fc30bbdf 95 byte lowByte(short int low);
aluqard 0:3b83fc30bbdf 96 byte highByte(short int high);
aluqard 0:3b83fc30bbdf 97
aluqard 0:3b83fc30bbdf 98 int random(int number);
aluqard 0:3b83fc30bbdf 99 int random(int numberone, int numbertwo);
aluqard 0:3b83fc30bbdf 100 #endif