Project works on the Arduino but when moved to Attiny85 it doesn't work as well

I'll give you a bit of background first, I'm a bit of a general Modder with no real concrete skills in any area but like to have a play and usual do ok with a bit of google / forum finding.
A few months ago a friend asked me to take a look at some simple soldering for him to repair a xbox 360 pad for his kids birthday as he broke the rapidfire chip wiring when replacing the outer case. He would have liked a couple more pads for when his mates come over but didn't want one of the super multi mode chips which are available on eBay etc, so this got me thinking it can't be too hard to knock something basic up and throw it on a attiny85 as I've got a few spares.
So having played for a bit, I got this code below to work well via the Arduino when hooked up to a pad for testing.

//const int ledpin = 13;
const int LbuttonPin = 2;
const int Ltriggerpin = 3;
const int RbuttonPin = 4;
const int Rtriggerpin = 5;

void setup() {
//  pinMode(ledpin, OUTPUT);
  pinMode(LbuttonPin, INPUT);
  pinMode(RbuttonPin, INPUT);
  
  pinMode(Ltriggerpin, OUTPUT);
  pinMode(Rtriggerpin, OUTPUT);
  randomSeed(analogRead(4));
}
void loop(){
//  LbuttonState = digitalRead(LbuttonPin);
  if ((digitalRead(RbuttonPin) == HIGH) && (digitalRead(LbuttonPin) == HIGH)){
//    digitalWrite(ledpin, HIGH);
    analogWrite(Rtriggerpin, 100);
    delay(40);
    analogWrite(Ltriggerpin, 100);
    delay(random(40, 60));
    analogWrite(Rtriggerpin, 0);
    analogWrite(Ltriggerpin, 0);
  } else { 
    if (digitalRead(RbuttonPin) == HIGH) {     
//      digitalWrite(ledpin, HIGH);
      analogWrite(Rtriggerpin, 100);
      delay(random(50, 60));
      analogWrite(Rtriggerpin, 0);
    }
    if (digitalRead(LbuttonPin) == HIGH) {     
//      digitalWrite(ledpin, HIGH);
      analogWrite(Ltriggerpin, 100);
      delay(random(50, 60));
      analogWrite(Ltriggerpin, 0);
    }
  }
  
//  digitalWrite(ledpin, LOW);
  analogWrite(Ltriggerpin, 0);
  analogWrite(Rtriggerpin, 0);
}

I changed the pins to those below and transferred it to the Attiny85 using the ArduinoISP (as 1MHz) and overall it worked ok.

const int LbuttonPin = 2; //2
const int Ltriggerpin = 0; //0
const int RbuttonPin = 3; //3
const int Rtriggerpin = 1; //1

Problem I'm finding is where the action of firing the gun comes in, its was timed lovely on the Arduino but on the attiny85 its very hit and miss. It will shoot 3 or 4 times very rapid then it will be like it misses a few goes then just a single shot, then a couple together.
As the code works on the Arduino I expect its my lack of attiny85 knowledge tripping me up so I've after some suggestions on how best to troubleshoot it. If you need the breadboard layout let me know and I'll try to put something together.

Do you have pulldown resistors on the trigger input pins ?
Apart from that it may be in the delay
try putting " cli(); " at the beginning of your loop code

You say you burned the tiny85 for 1MHz but the arduino cores are really only suited for 8/16MHz. If you do the burn bootloader thing (it does not burn a bootloader but sets the fuses) using ArduinoISP so the tiny85 is using internal 8MHz instead of the default 1MHz your timings should become less erratic.

Are the delay() lines adjusted for the slower chip ?

are they required at all ?

You probably have the wrong clock speed set.

The Tiny85 can run at 16Mhz with internal clock but you need to set the correct fuse bits in "boards.txt" then do "burn bootloader" to set them.

Its sounding very like its the burn bootloader bit I maybe missing then as I presumed when you select the board from the tools menu as 'ATtiny85 (Internal 8 MHz clock)' that was telling the board to run at 8MHz (or 1MHz depending on whats selected).

The selection of boards doesn't list a 16MHz, only 1,8 and 20MHz - Can I just edit the boards.txt to give me another option? Once the fuses is 'burnt', is that chip then locked at that clock rate or can it be 'burnt' back to another speed if required?

I've adjusted the timings on the delays to play around without any real success, its the lack of consistency which is the main issue with the timing, almost like it forgets how to count mid way running lol.

mcnobby - to answer the resistor question, yes I've got 10K resistors on the inputs for the tactile pins, and also 10k resistors on the output lines to the xbox pad as without it interfered with other pad controls.

So very quickly selected the 8MHz board from the Tools menu, did the 'Burn Bootloader' bit and reloaded the sketch - hey presto! works a treat now!

Really goes to show how important the little details are! Cheers guys :slight_smile: