ATtiny45 controlling a servo through touch capacitance

Hello.

Sorry if this is an obvious fix but I’ve been working on this project for 2 months and now feel like I’m banging my head against a brick wall and could do with some guidance.

I’m trying to controll a Servo (SG90) using Touch Capacitance through an ATtiny45 chip to open and close a box, all while having an LED pulsating.

Currently I had the code working on the Arduino Uno board using the Servo.h library but didn’t realise that this wasn’t compatable with the ATtiny chip (I might also add I’ve self taught myself this code in 2 months through google and trial and error so my knowledge of this is very limited).

I’ve tried changing the library to SoftwareServo.h and made the appropriate changes (Changing #include <Wprogram.h> to #include <Arduino.h>) but for some reason the Servo part of the code just doesn’t run, even though it compiles with no errors; the LED does flash as intended.

The code is here:

#include <SoftwareServo.h>
#include <CapacitiveSensor.h>

CapacitiveSensor cs_4_8 = CapacitiveSensor(4, 8);
SoftwareServo myservo;
int angle = 10;
int led = 3;
int brightness = 0;
int fadeAmount = 5;


void setup() 
{
  cs_4_8.set_CS_AutocaL_Millis(0xFFFFFFFF);
  
  pinMode(2, OUTPUT);
  pinMode(led, OUTPUT);
  myservo.attach(9);
  Serial.begin(9600);
  myservo.write(10);
}

void loop() 
{
  //LED flash
  analogWrite(led, brightness);
  brightness = brightness + fadeAmount;
  if (brightness <= 0 || brightness >= 255)
        {
            fadeAmount = -fadeAmount;
        }
  delay(35);

  //Touch Sensor
  long sensor1 = cs_4_8.capacitiveSensor(50);
  Serial.println(sensor1);

  //Servo Code
  if (sensor1 >= 500)
  {
    //runs this first
     digitalWrite(2, HIGH);
     delay(900);
     if (angle == 10)
     { 

     for (; angle < 180; angle +=1) //goes from 0 to 180 degrees in steps of 1 degree
       {
         myservo.write(angle); //directs servo to go to position in variable 'angle'  
         delay(5);
         SoftwareServo::refresh();
       }
     angle=180;
     } 
     
     else if (angle == 180) 
     {
     
      for (; angle > 10; angle -=1) //goes from 0 to 180 degrees in steps of 1 degree
         {
           myservo.write(angle); //directs servo to go to position in variable 'angle'   
           delay(5); 
           SoftwareServo::refresh();
         }
        angle=10;
      }

     }
}

Any help or guidance on how to get this working would be greatly appreciated.
Thank you.

The servo8bit library is a servo library for the tiny85 and 45 processors.

When I change to the Servo8bit.h I get these errors:

C:\Users\____\Documents\Arduino\libraries\Servo8Bit-master\Servo8Bit.cpp: In static member function 'static void ServoSequencer::servoTimerSetup()':

C:\Users\____\Documents\Arduino\libraries\Servo8Bit-master\Servo8Bit.cpp:458:5: error: 'TIMSK' was not declared in this scope

     TIMSK |= (1 << OCIEnx);

     ^

C:\Users\____\Documents\Arduino\libraries\Servo8Bit-master\Servo8Bit.cpp: In static member function 'static void ServoSequencer::setupTimerPrescaler()':

C:\Users\____\Documents\Arduino\libraries\Servo8Bit-master\Servo8Bit.cpp:517:9: error: 'TCCR1' was not declared in this scope

         TCCR1 = 0;

         ^

C:\Users\____\Documents\Arduino\libraries\Servo8Bit-master\Servo8Bit.cpp: In static member function 'static void ServoSequencer::timerCompareMatchISR()':

C:\Users\____\Documents\Arduino\libraries\Servo8Bit-master\Servo8Bit.cpp:636:13: error: 'TIFR' was not declared in this scope

             TIFR = (1 << OCF0A);  // write logical 1 to the OCF0A flag to clear it

             ^

exit status 1
Error compiling for board Arduino/Genuino Uno.

I don’t know what they mean.

Which tiny core are you using?

It's the ATtiny45.