mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-17 22:23:10 +03:00
Adding map(), fixing radians() and degrees(), adding cast functions (int(x) instead of (int) x), adding interrupts() and noInterrupts(), etc.
This commit is contained in:
@ -116,7 +116,7 @@
|
|||||||
productName = App;
|
productName = App;
|
||||||
productReference = 33DD8FB6096AC8DA0013AF8F /* Arduino.app */;
|
productReference = 33DD8FB6096AC8DA0013AF8F /* Arduino.app */;
|
||||||
productSettingsXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
|
productSettingsXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
|
||||||
<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
|
<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
|
||||||
<plist version=\"1.0\">
|
<plist version=\"1.0\">
|
||||||
<dict>
|
<dict>
|
||||||
<key>CFBundleDevelopmentRegion</key>
|
<key>CFBundleDevelopmentRegion</key>
|
||||||
@ -903,6 +903,7 @@
|
|||||||
33FFFD3F0965B1E40016AC38 /* Project object */ = {
|
33FFFD3F0965B1E40016AC38 /* Project object */ = {
|
||||||
isa = PBXProject;
|
isa = PBXProject;
|
||||||
buildConfigurationList = 33FFFD400965B1E40016AC38 /* Build configuration list for PBXProject "Arduino" */;
|
buildConfigurationList = 33FFFD400965B1E40016AC38 /* Build configuration list for PBXProject "Arduino" */;
|
||||||
|
compatibilityVersion = "Xcode 2.4";
|
||||||
hasScannedForEncodings = 0;
|
hasScannedForEncodings = 0;
|
||||||
mainGroup = 33FFFD3D0965B1E40016AC38;
|
mainGroup = 33FFFD3D0965B1E40016AC38;
|
||||||
productRefGroup = 33FFFD3D0965B1E40016AC38;
|
productRefGroup = 33FFFD3D0965B1E40016AC38;
|
||||||
@ -913,6 +914,7 @@
|
|||||||
ProjectRef = 33FFFE940965BD110016AC38 /* Arduino.xcodeproj */;
|
ProjectRef = 33FFFE940965BD110016AC38 /* Arduino.xcodeproj */;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
projectRoot = "";
|
||||||
targets = (
|
targets = (
|
||||||
33FFFE1C0965BBEF0016AC38 /* Setup */,
|
33FFFE1C0965BBEF0016AC38 /* Setup */,
|
||||||
33AF61680965C4C600B514A9 /* App */,
|
33AF61680965C4C600B514A9 /* App */,
|
||||||
|
@ -165,5 +165,6 @@ printBinary KEYWORD2
|
|||||||
printNewline KEYWORD2
|
printNewline KEYWORD2
|
||||||
pulseIn KEYWORD2
|
pulseIn KEYWORD2
|
||||||
shiftOut KEYWORD2
|
shiftOut KEYWORD2
|
||||||
|
map KEYWORD2
|
||||||
random KEYWORD2
|
random KEYWORD2
|
||||||
randomSeed KEYWORD2
|
randomSeed KEYWORD2
|
@ -52,3 +52,7 @@ long random(long howsmall, long howbig)
|
|||||||
return random(diff) + howsmall;
|
return random(diff) + howsmall;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long map(long x, long in_min, long in_max, long out_min, long out_max)
|
||||||
|
{
|
||||||
|
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
|
||||||
|
}
|
@ -10,8 +10,9 @@
|
|||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#include "HardwareSerial.h"
|
#include "HardwareSerial.h"
|
||||||
|
|
||||||
// random prototypes
|
// WMath prototypes
|
||||||
long random(long);
|
long random(long);
|
||||||
long random(long, long);
|
long random(long, long);
|
||||||
void randomSeed(unsigned int);
|
void randomSeed(unsigned int);
|
||||||
|
long map(long, long, long, long, long);
|
||||||
#endif
|
#endif
|
||||||
|
@ -44,6 +44,8 @@ extern "C"{
|
|||||||
#define PI 3.14159265
|
#define PI 3.14159265
|
||||||
#define HALF_PI 1.57079
|
#define HALF_PI 1.57079
|
||||||
#define TWO_PI 6.283185
|
#define TWO_PI 6.283185
|
||||||
|
#define DEG_TO_RAD 0.01745329
|
||||||
|
#define RAD_TO_DEG 57.2957786
|
||||||
|
|
||||||
#define SERIAL 0x0
|
#define SERIAL 0x0
|
||||||
#define DISPLAY 0x1
|
#define DISPLAY 0x1
|
||||||
@ -55,14 +57,30 @@ extern "C"{
|
|||||||
#define FALLING 2
|
#define FALLING 2
|
||||||
#define RISING 3
|
#define RISING 3
|
||||||
|
|
||||||
|
// undefine stdlib's abs if encountered
|
||||||
|
#ifdef abs
|
||||||
|
#undef abs
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define int(x) ((int)(x))
|
||||||
|
#define char(x) ((char)(x))
|
||||||
|
#define long(x) ((long)(x))
|
||||||
|
#define byte(x) ((uint8_t)(x))
|
||||||
|
#define float(x) ((float)(x))
|
||||||
|
#define boolean(x) ((uint8_t)((x)==0?0:1))
|
||||||
|
|
||||||
#define min(a,b) ((a)<(b)?(a):(b))
|
#define min(a,b) ((a)<(b)?(a):(b))
|
||||||
#define max(a,b) ((a)>(b)?(a):(b))
|
#define max(a,b) ((a)>(b)?(a):(b))
|
||||||
#define abs(x) ((x)>0?(x):-(x))
|
#define abs(x) ((x)>0?(x):-(x))
|
||||||
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
|
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
|
||||||
|
#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
|
||||||
#define radians(deg) ((deg)*DEG_TO_RAD)
|
#define radians(deg) ((deg)*DEG_TO_RAD)
|
||||||
#define degrees(rad) ((rad)*RAD_TO_DEG)
|
#define degrees(rad) ((rad)*RAD_TO_DEG)
|
||||||
#define sq(x) ((x)*(x))
|
#define sq(x) ((x)*(x))
|
||||||
|
|
||||||
|
#define interrupts() sei()
|
||||||
|
#define noInterrupts() cli()
|
||||||
|
|
||||||
#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
|
#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
|
||||||
#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )
|
#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user