2 wiring.h - Partial implementation of the Wiring API for the ATmega8.
\r
3 Part of Arduino - http://www.arduino.cc/
\r
5 Copyright (c) 2005-2006 David A. Mellis
\r
7 This library is free software; you can redistribute it and/or
\r
8 modify it under the terms of the GNU Lesser General Public
\r
9 License as published by the Free Software Foundation; either
\r
10 version 2.1 of the License, or (at your option) any later version.
\r
12 This library is distributed in the hope that it will be useful,
\r
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
\r
15 Lesser General Public License for more details.
\r
17 You should have received a copy of the GNU Lesser General
\r
18 Public License along with this library; if not, write to the
\r
19 Free Software Foundation, Inc., 59 Temple Place, Suite 330,
\r
20 Boston, MA 02111-1307 USA
\r
45 #define PI 3.1415926535897932384626433832795
\r
46 #define HALF_PI 1.5707963267948966192313216916398
\r
47 #define TWO_PI 6.283185307179586476925286766559
\r
48 #define DEG_TO_RAD 0.017453292519943295769236907684886
\r
49 #define RAD_TO_DEG 57.295779513082320876798154814105
\r
61 #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
\r
62 #define INTERNAL1V1 2
\r
63 #define INTERNAL2V56 3
\r
70 // undefine stdlib's abs if encountered
\r
75 #define min(a,b) ((a)<(b)?(a):(b))
\r
76 #define max(a,b) ((a)>(b)?(a):(b))
\r
77 #define abs(x) ((x)>0?(x):-(x))
\r
78 #define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
\r
79 #define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
\r
80 #define radians(deg) ((deg)*DEG_TO_RAD)
\r
81 #define degrees(rad) ((rad)*RAD_TO_DEG)
\r
82 #define sq(x) ((x)*(x))
\r
84 #define interrupts() sei()
\r
85 #define noInterrupts() cli()
\r
87 #define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
\r
88 #define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )
\r
89 #define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() )
\r
91 #define lowByte(w) ((uint8_t) ((w) & 0xff))
\r
92 #define highByte(w) ((uint8_t) ((w) >> 8))
\r
94 #define bitRead(value, bit) (((value) >> (bit)) & 0x01)
\r
95 #define bitSet(value, bit) ((value) |= (1UL << (bit)))
\r
96 #define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
\r
97 #define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
\r
99 typedef unsigned int word;
\r
101 #define bit(b) (1UL << (b))
\r
103 typedef uint8_t boolean;
\r
104 typedef uint8_t byte;
\r
108 void pinMode(uint8_t, uint8_t);
\r
109 void digitalWrite(uint8_t, uint8_t);
\r
110 int digitalRead(uint8_t);
\r
111 int analogRead(uint8_t);
\r
112 void analogReference(uint8_t mode);
\r
113 void analogWrite(uint8_t, int);
\r
115 unsigned long millis(void);
\r
116 unsigned long micros(void);
\r
117 void delay(unsigned long);
\r
118 void delayMicroseconds(unsigned int us);
\r
119 unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout);
\r
121 void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);
\r
122 uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder);
\r
124 void attachInterrupt(uint8_t, void (*)(void), int mode);
\r
125 void detachInterrupt(uint8_t);
\r