8 #include <avr/pgmspace.h>
10 #include <avr/interrupt.h>
23 #define INPUT_PULLUP 0x2
28 #define PI 3.1415926535897932384626433832795
29 #define HALF_PI 1.5707963267948966192313216916398
30 #define TWO_PI 6.283185307179586476925286766559
31 #define DEG_TO_RAD 0.017453292519943295769236907684886
32 #define RAD_TO_DEG 57.295779513082320876798154814105
44 #if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
49 #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1284P__)
51 #define INTERNAL2V56 3
59 // undefine stdlib's abs if encountered
64 #define min(a,b) ((a)<(b)?(a):(b))
65 #define max(a,b) ((a)>(b)?(a):(b))
66 #define abs(x) ((x)>0?(x):-(x))
67 #define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
68 #define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
69 #define radians(deg) ((deg)*DEG_TO_RAD)
70 #define degrees(rad) ((rad)*RAD_TO_DEG)
71 #define sq(x) ((x)*(x))
73 #define interrupts() sei()
74 #define noInterrupts() cli()
76 #define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
77 #define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )
78 #define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() )
80 #define lowByte(w) ((uint8_t) ((w) & 0xff))
81 #define highByte(w) ((uint8_t) ((w) >> 8))
83 #define bitRead(value, bit) (((value) >> (bit)) & 0x01)
84 #define bitSet(value, bit) ((value) |= (1UL << (bit)))
85 #define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
86 #define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
89 typedef unsigned int word;
91 #define bit(b) (1UL << (b))
93 typedef uint8_t boolean;
98 void pinMode(uint8_t, uint8_t);
99 void digitalWrite(uint8_t, uint8_t);
100 int digitalRead(uint8_t);
101 int analogRead(uint8_t);
102 void analogReference(uint8_t mode);
103 void analogWrite(uint8_t, int);
105 unsigned long millis(void);
106 unsigned long micros(void);
107 void delay(unsigned long);
108 void delayMicroseconds(unsigned int us);
109 unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout);
111 void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);
112 uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder);
114 void attachInterrupt(uint8_t, void (*)(void), int mode);
115 void detachInterrupt(uint8_t);
120 // Get the bit location within the hardware port of the given virtual pin.
121 // This comes from the pins_*.c file for the active board configuration.
123 #define analogInPinToBit(P) (P)
125 // On the ATmega1280, the addresses of some of the port registers are
126 // greater than 255, so we can't store them in uint8_t's.
127 extern const uint16_t PROGMEM port_to_mode_PGM[];
128 extern const uint16_t PROGMEM port_to_input_PGM[];
129 extern const uint16_t PROGMEM port_to_output_PGM[];
131 extern const uint8_t PROGMEM digital_pin_to_port_PGM[];
132 // extern const uint8_t PROGMEM digital_pin_to_bit_PGM[];
133 extern const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[];
134 extern const uint8_t PROGMEM digital_pin_to_timer_PGM[];
136 // Get the bit location within the hardware port of the given virtual pin.
137 // This comes from the pins_*.c file for the active board configuration.
139 // These perform slightly better as macros compared to inline functions
141 #define digitalPinToPort(P) ( pgm_read_byte( digital_pin_to_port_PGM + (P) ) )
142 #define digitalPinToBitMask(P) ( pgm_read_byte( digital_pin_to_bit_mask_PGM + (P) ) )
143 #define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) )
144 #define analogInPinToBit(P) (P)
145 #define portOutputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_output_PGM + (P))) )
146 #define portInputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_input_PGM + (P))) )
147 #define portModeRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_mode_PGM + (P))) )
166 #define NOT_ON_TIMER 0
191 #include "WCharacter.h"
193 #include "HardwareSerial.h"
195 uint16_t makeWord(uint16_t w);
196 uint16_t makeWord(byte h, byte l);
198 #define word(...) makeWord(__VA_ARGS__)
200 unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);
202 void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0);
203 void noTone(uint8_t _pin);
207 long random(long, long);
208 void randomSeed(unsigned int);
209 long map(long, long, long, long, long);
213 #include "pins_arduino.h"