Go Down

Topic: attiny random delay (Read 479 times) previous topic - next topic

hilukasz

Mar 09, 2013, 07:24 am Last Edit: Mar 09, 2013, 08:56 am by hilukasz Reason: 1
trying to implement some timing things with several LEDs and I have tested the code on arduino and it seems to work fine, so I am very confused. I change the pins to go back to my attiny and it seems to not work. no idea why.

Code: [Select]
const byte fadeUpEvery = 2,
          fadeInSpeed = 5,
          sampleAmount = 5,
          capacitiveSensorOutput = 2,
          capacitiveSensorInput = 3;

int highLow,
   delayTime,
   numberTimes,
   counter,
   ledNumCount;

int led[] = { 0, 1, 4 };
//int led[] = { 2, 3, 4 };
         
const int delayMin = 4000,
         delayMax = 9000;

void setup(){

  isOn = true;  
  toggleLED = false;
  highLow = LOW;
  counter = 0;
  makeLightningTimer = millis();
  ledNumCount = 0;
 
  for(int i = 0; i < 3; i++){
    pinMode(led[i],OUTPUT);
  }
}

void loop(){
    makeLightning();
}

void makeLightning(){
 int delayInterval = random(delayMin,delayMax);
 
 int timeDiff = millis() - makeLightningTimer;
 if( timeDiff >= delayInterval){
   int numberTimes = random(1, 4);
   // normal flicker
   if(counter != fadeUpEvery){
     for(int k = 0; k < numberTimes; k++){
       digitalWrite(led[ledNumCount], LOW);
       delay(500);
       digitalWrite(led[ledNumCount],HIGH);
       delay(500);
       digitalWrite(led[ledNumCount], LOW);
     }
   }
   if(counter == fadeUpEvery){
     counter = 0;
     fade(led[ledNumCount]);
   }
 }
 makeLightningTimer = millis();
 counter++;
 ledNumCount++;
 
 if(ledNumCount >= 3) {
    ledNumCount = 0;
 }
}


this is a trimmed version of the code because the sketch is really big. let me know if it helps to see entire thing. it's in the makeLightning that the funny business is happening, I am assuming. Been stuck on this on for quite some time now...

on arduino it works fine, attiny it flickers first LED, then stops.

EDIT: figured it out, it has to do with a capacitive sensor I am using with it. its making it do some funny things...?
for(i = 0, i < 820480075, i++){ Design(); Code(); delay(1000); } // hellowoo.com

afremont

Thank you for reporting back and actually saying what the issue was.  :)
Experience, it's what you get when you were expecting something else.

Go Up