Datasheet
Programming with Arduino IDE
Once you've gotten the basic Blink example to work, you can try some of the other Arduino functions and libraries.
We'll be filling out this section with more example code and links to tutorials - this is just to get you started!
pinMode() & digitalWrite() & digitalRead()
You can use pinMode() to make inputs and outputs on any of digital pins #0 thru #4
digitalWrite also works well, and you can also use it with pinMode(INPUT) to activate the internal pull-up resistor on a
pin
For example, to set up digital #0 as an input, with an internal pullup, and then check if it is being pulled to ground via a
button or switch and turn on the red LED when it is pressed:
analogRead()
You can read an analog voltage from digital #2 (called Analog 1), digital #3 (called Analog 3) and digital #4 (called
Analog 2)
/*
Button
Turns on an LED when a switch connected from #0 to ground is pressed
This example code is in the public domain.
To upload to your Gemma or Trinket:
1) Select the proper board from the Tools->Board Menu
2) Select USBtinyISP from the Tools->Programmer
3) Plug in the Gemma/Trinket, make sure you see the green LED lit
4) For windows, install the USBtiny drivers
5) Press the button on the Gemma/Trinket - verify you see
the red LED pulse. This means it is ready to receive data
6) Click the upload button above within 10 seconds
*/
#define SWITCH 0
#define LED 1
// the setup routine runs once when you press reset:
void setup() {
// initialize the LED pin as an output.
pinMode(LED, OUTPUT);
// initialize the SWITCH pin as an input with a pullup
pinMode(SWITCH, INPUT_PULLUP);
}
// the loop routine runs over and over again forever:
void loop() {
if (! digitalRead(SWITCH)) { // if the button is pressed
digitalWrite(LED, HIGH); // light up the LED
} else {
digitalWrite(LED, LOW); // otherwise, turn it off
}
}
© Adafruit Industries https://learn.adafruit.com/introducing-trinket Page 22 of 43