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.h
00001 #ifndef _ARDUINO_H_ 00002 #define _ARDUINO_H_ 00003 00004 #include "mbed.h" 00005 #include "math.h" 00006 // Macros 00007 //add by gastonfeng begin 00008 typedef enum WiringPinMode 00009 { 00010 OUTPUT, /**< Basic digital output: when the pin is HIGH, the 00011 voltage is held at +3.3v (Vcc) and when it is LOW, it 00012 is pulled down to ground. */ 00013 00014 OUTPUT_OPEN_DRAIN, /**< In open drain mode, the pin indicates 00015 "low" by accepting current flow to ground 00016 and "high" by providing increased 00017 impedance. An example use would be to 00018 connect a pin to a bus line (which is pulled 00019 up to a positive voltage by a separate 00020 supply through a large resistor). When the 00021 pin is high, not much current flows through 00022 to ground and the line stays at positive 00023 voltage; when the pin is low, the bus 00024 "drains" to ground with a small amount of 00025 current constantly flowing through the large 00026 resistor from the external supply. In this 00027 mode, no current is ever actually sourced 00028 from the pin. */ 00029 00030 INPUT, /**< Basic digital input. The pin voltage is sampled; when 00031 it is closer to 3.3v (Vcc) the pin status is high, and 00032 when it is closer to 0v (ground) it is low. If no 00033 external circuit is pulling the pin voltage to high or 00034 low, it will tend to randomly oscillate and be very 00035 sensitive to noise (e.g., a breath of air across the pin 00036 might cause the state to flip). */ 00037 00038 INPUT_ANALOG, /**< This is a special mode for when the pin will be 00039 used for analog (not digital) reads. Enables ADC 00040 conversion to be performed on the voltage at the 00041 pin. */ 00042 00043 INPUT_PULLUP, /**< The state of the pin in this mode is reported 00044 the same way as with INPUT, but the pin voltage 00045 is gently "pulled up" towards +3.3v. This means 00046 the state will be high unless an external device 00047 is specifically pulling the pin down to ground, 00048 in which case the "gentle" pull up will not 00049 affect the state of the input. */ 00050 00051 INPUT_PULLDOWN, /**< The state of the pin in this mode is reported 00052 the same way as with INPUT, but the pin voltage 00053 is gently "pulled down" towards 0v. This means 00054 the state will be low unless an external device 00055 is specifically pulling the pin up to 3.3v, in 00056 which case the "gentle" pull down will not 00057 affect the state of the input. */ 00058 00059 INPUT_FLOATING, /**< Synonym for INPUT. */ 00060 00061 PWM, /**< This is a special mode for when the pin will be used for 00062 PWM output (a special case of digital output). */ 00063 00064 PWM_OPEN_DRAIN, /**< Like PWM, except that instead of alternating 00065 cycles of LOW and HIGH, the voltage on the pin 00066 consists of alternating cycles of LOW and 00067 floating (disconnected). */ 00068 } WiringPinMode; 00069 00070 // Roger Clark. Added _BV macro for AVR compatibility. As requested by @sweetlilmre and @stevestrong 00071 #ifndef _BV 00072 #define _BV(bit) (1 << (bit)) 00073 #endif 00074 #define HIGH 1 00075 #define LOW 0 00076 #define digitalRead(x) x 00077 #define digitalWrite(a, b) a->write(b) 00078 void *pinMode(PinName pin, uint8_t f); 00079 //gastonfeng end 00080 00081 #define PI 3.1415926535897932384626433832795 00082 #define HALF_PI 1.5707963267948966192313216916398 00083 #define TWO_PI 6.283185307179586476925286766559 00084 #define DEG_TO_RAD 0.017453292519943295769236907684886 00085 #define RAD_TO_DEG 57.295779513082320876798154814105 00086 00087 #define radians(deg) ((deg)*DEG_TO_RAD) 00088 #define degrees(rad) ((rad)*RAD_TO_DEG) 00089 #define sq(x) ((x)*(x)) 00090 00091 #define pgm_read_word(x) (*(const short int*)x) 00092 #define pgm_read_dword_near(x) (*(const int*)x) 00093 #define pgm_read_word_near(x) (*(const unsigned int*)x) 00094 #define pgm_read_int_near(x) (*(const int*)x) 00095 #define pgm_read_int(x) (*(const int*)x) 00096 #define pgm_read_byte(x) (*(const char*)x) 00097 #define pgm_read_byte_near(x) (*(const char*)x) 00098 #define PROGMEM const 00099 #define char(x) ((char)x) 00100 #define byte(x) ((byte)x) 00101 #define int(x) ((int)x) 00102 #define word(x) ((word)x) 00103 #define long(x) ((long)x) 00104 #define float(x) ((float)x) 00105 00106 #define in_range(c, lo, up) ((uint8_t)c >= lo && (uint8_t)c <= up) 00107 #define isprint(c) in_range(c, 0x20, 0x7f) 00108 #define isdigit(c) in_range(c, '0', '9') 00109 #define isxdigit(c) (isdigit(c) || in_range(c, 'a', 'f') || in_range(c, 'A', 'F')) 00110 #define islower(c) in_range(c, 'a', 'z') 00111 #define isspace(c) (c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v') 00112 00113 /** Macro for delay() 00114 * 00115 * @param void 00116 */ 00117 #define delay(x) (wait_ms(x)) 00118 /** Macro for delayMicroseconds() 00119 * 00120 * @param void 00121 */ 00122 #define delayMicroseconds(x) (wait_us(x)) 00123 00124 /** Macro for min() 00125 * 00126 * @param any 00127 */ 00128 #define min(a,b) ((a)<(b)?(a):(b)) 00129 /** Macro for max() 00130 * 00131 * @param any 00132 */ 00133 #define max(a,b) ((a)>(b)?(a):(b)) 00134 /** Macro for abs() 00135 * 00136 * @param any 00137 */ 00138 #define abs(x) ((x)>0?(x):(x*-1)) 00139 00140 /** Macro for randomSeed() 00141 * 00142 * @param int 00143 */ 00144 #define randomSeed(x) srand(x) 00145 00146 #define bitRead(value, bit) (((value) >> (bit)) & 0x01) 00147 #define bitSet(value, bit) ((value) |= (1UL << (bit))) 00148 #define bitClear(value, bit) ((value) &= ~(1UL << (bit))) 00149 #define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit)) 00150 00151 // typedefs 00152 00153 typedef unsigned char prog_uchar; 00154 typedef unsigned char prog_uint8_t; 00155 typedef unsigned int prog_uint16_t; 00156 typedef unsigned int prog_uint32_t; 00157 typedef unsigned char byte; 00158 typedef bool boolean; 00159 typedef unsigned char prog_uchar; 00160 typedef signed char prog_char; 00161 typedef signed long int word; 00162 00163 // function prototypes 00164 00165 void timer_start(void); 00166 long millis(void); 00167 long micros(void); 00168 byte lowByte(short int low); 00169 byte highByte(short int high); 00170 00171 int random(int number); 00172 int random(int numberone, int numbertwo); 00173 #endif
Generated on Sun Aug 14 2022 23:40:23 by
1.7.2
