Hi folks
I am struggling with the digispark attiny85. I am using the arduino IDE 1.6.5. My code works, kind of. It is supposed to go on and off on pin0 every 1sec but it takes around 8-10sec! I have been reading about the attiny not having a crystal and using an OSC being a problem with incorrect timing but reported error is 5-10%. Mine is a whopping 800-1000% error! I know, most likely I am doing something silly. Any help greatly appreciated.
Code below:
int sw1=1;
int sw2=2;
int sw3=3;
int sw4=4;
int bz=0;
unsigned long lastm=0;
unsigned long curm=0;
long interval=1000;
void setup() {
// put your setup code here, to run once:
for (int n=1;n<5;n++){
pinMode(n, INPUT_PULLUP);
}
pinMode(bz,OUTPUT);
}
int timeforact(){
curm=millis();
if (curm-lastm>interval){
lastm=curm;
return 1;
}
else { return 0; }
}
void loop() {
// put your main code here, to run repeatedly:
if (timeforact()==1) {digitalWrite(bz,HIGH); }
if (timeforact()==1) {digitalWrite(bz,LOW); }
}