This is a first experiment burning an Arduino sketch into an ATTiny85 microcontroller. This time we will have an analog input which will control an analog output.
Step by step you should:
- Upload Arduino as ISP sketch into your Arduino UNO or similar
- Connect everything
- "Burn Arduino"
- Fuses are set
- flash ArduinoBootloader
- Select programmer "Arduino as ISP"
- Upload using programmer
- Upload your sketch using programmer.
According with the ATTiny85's pinout schematic
We have 5 digital pins (blue ones) and 3 analog pin (red ones) which is enough for our little example. Let put a force resistor (analog input 0 - 1023) in order to control a fading LED (which receives 0 - 255).
//ARDUINO CODE int led = 1; // the PWM pin the LED is attached to int forceR = A1; // Pin 2 = A1 according to pinout int force; // the setup routine runs once when you press reset: void setup() { // declare pin 9 to be an output: pinMode(led, OUTPUT); } // the loop routine runs over and over again forever: void loop() { force = analogRead(forceR); brightness = map(force, 0, 1023, 0, 255); // LED gets brighter the harder you press analogWrite(led, brightness); }