/******************************************************************* This sketch is based on an example from AdaFruit for the Trinket and adapted for the ATTiny 45 *******************************************************************/ #include // SoftwareServo (works on non PWM pins) #define SERVO1PIN 3 // Servo control line goes to (Arduino Pin A3/3) ATTiny45 Pin 2 #define POTPIN 1 // Potentiometer sweep (center) (Arduino Pin A1/2/SCK) ATTiny45 Pin7 Adafruit_SoftServo myServo1 //create a servo object int potValue; // variable to read potentiometer int servoPos; // variable to convert voltage on pot to servo position void setup() { // Set up the interrupt that will refresh the servo for us automagically OCR0A = 0xAF; // any number is OK TIMSK |= _BV(OCIE0A); // Turn on the compare interrupt (below!) myServo1.attach(SERVO1PIN); // Attach the servo to (Arduino Pin A3/3) ATTiny45 Pin 2 myServo1.write(90); // Tell servo to go to position per quirk delay(15); // Wait 15ms for the servo to reach the position } void loop() { potValue=analogRead(POTPIN); // Read voltage on potentiometer servoPos = map(potValue, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180) myServo1.write(servoPos); // tell servo to go to position delay(15); // waits 15ms for the servo to reach the position } // We'll take advantage of the built in millis() timer that goes off // to keep track of time, and refresh the servo every 20 milliseconds volatile uint8_t counter = 0; SIGNAL(TIMER0_COMPA_vect) { // this gets called every 2 milliseconds counter += 2; // every 20 milliseconds, refresh the servos! if (counter >= 20) { counter = 0; myServo1.refresh(); myServo2.refresh(); } }