You are on page 1of 1

Sparkfun Electronics ATtiny85 Arduino Quick Reference Sheet

ATtiny85
Structure Digital I/O
/* Each Arduino sketch must contain the digitalWrite(pin, val);
following two functions. */
/* val = HIGH or LOW write a HIGH or a LOW ATtiny85 Pins
value to a digital pin. */
void setup() Pins 0 – 4 : general purpose I/O pins
{ // this code runs once at the buttonVal = digitalRead(pin); (GPIO).
// beginning of the code execution.
} /* Reads the value from a specified digital Both digitalWrite() and digitalRead()
pin, either HIGH or LOW. */ can be used with any of these pins.
void loop()
{ // this code runs repeatedly over Analog I/O Pins 0 & 1 : setup for PWM output
using analogWrite().
// and over as long as the board is analogWrite(pin, val);
// powered. Pins A1, A2, A3 : setup for reading
} /* Writes an analog voltage (using PWM) to a
sensor input with analogRead().
pin. val = integer value from 0 to 255 */

Comments sensorVal = analogRead(pin); Data Types


// this is a single line comment /* Reads the voltage from the specified
/* this is void // nothing is returned
analog pin. 0V returns 0; Vcc returns 1023*/
boolean // 0, 1, false, true
a multiline
char // 8 bits: -128 to 127
comment */ Time byte // 8 bits: 0 to 255
delay(time_ms); int // 16 bits: -32,768 to 32,767
Setup /* Pauses the program for the amount of time unsigned int // 16 bits (unsigned)
pinMode(pinNum, INPUT/OUTPUT/INPUT_PULLUP); (in milliseconds). */ long /* 32 bits: -2,147,483,648
/* Sets the mode of the digital I/O pin. to 2,147,483,647 */
millis();
All pins are general I/O on the board. You unsigned long // 32 bits (unsigned)
/* Returns the number of milliseconds since
must define what the pin will be used for at
the board began running the current program. float // 32 bits, signed decimal
the beginning of your code in setup() */
max: 4,294,967,295 */

Control Structures
Serial Communication
if(condition) #include <SoftwareSerial.h> // include library
A separate USB to serial adapter like FTDI is
{ // if condition is true, do something here needed for Serial communication with the ATtiny. SoftwareSerial tinySerial(3, 4);
} And. the ATtiny must be flashed to run at 8 MHz /* Put above setup() and loop() – declares
else instead of 1 MHz. tinySerial using 3 & 4 for Transmit (tx) and
{ // otherwise, do this Receive (rx) */
The ATtiny does not support Serial natively. You
}
need to use the SoftwareSerial library to enable tinySerial.begin(9600); /* begin Serial at 9600
this function. baud. Put this line in setup() */
for(init; condition; increment)
{ tinySerial.print(“”); /* sends data on TX line
// do this, increment, and – to your receiving computer. */
// repeat while condition is true. tinySerial.println(“”); /* sends data to Serial
} Monitor with CRLF. */
inChar = tinySerial.read();

You might also like