Pages: [1]   Go Down
Author Topic: attiny random delay  (Read 456 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 3
Posts: 188
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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...?
« Last Edit: March 09, 2013, 02:56:59 am by hilukasz » Logged

for(i = 0, i < 820480075, i++){ Design(); Code(); delay(1000); } // hellowoo.com

texas
Offline Offline
God Member
*****
Karma: 27
Posts: 862
old, but not dead
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you for reporting back and actually saying what the issue was.  smiley
Logged

Experience, it's what you get when you were expecting something else.

Pages: [1]   Go Up
Jump to: