Professional Documents
Culture Documents
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 */
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();