ryanqq / arduino-tiny

Automatically exported from code.google.com/p/arduino-tiny
Other
0 stars 0 forks source link

2313 software defined current limit? #100

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. I have a sketch with an array of LEDs
2. LED array is defined as outputs
3. I use simple digitalWrite functions, with only a single LED ever being lit 
at once.

What is the expected output? What do you see instead?

I expect each led to simply turn on for a period of time at full brightness, 
however the 4th and beyond LEDs as defined only output a very dim light. If I 
switch the software order of the array, the previously dim LED will glow full 
brightness, but whichever LEDs are 4th 5th 6th etc. are always dim. the first 3 
LEDs function normally. 

LEDs are connected to physical pins 2, 4, 15, 16 for my particular project, but 
it doesn't matter which pins I tie into, anything beyond 3 LEDs will be dimmed 
to about 10% or less of full brightness...

What version of the product are you using? On what operating system?

latest arduino 1.0.5 on OSX 10.9 with the latest package of 
arduino-tiny-0100-0018

Please provide any additional information below.

all other outputs/inputs are working fine. for reference, heres the code for 
defining LEDS I am working with...

const int led[4]={2,12,13,0}; // physical pins 4, 15, 16, 2

in setup function

for (byte i = 0; i < 3; i = i + 1) {
    pinMode(led[i], OUTPUT);
  }

in the rest of the code I am simply using the digitalWrite command, only one 
LED at once...

Original issue reported on code.google.com by hatchina...@gmail.com on 2 Dec 2013 at 9:24

GoogleCodeExporter commented 9 years ago
Incomplete source code.

Original comment by arduino....@gmail.com on 2 Dec 2013 at 10:01

GoogleCodeExporter commented 9 years ago
here is my source code... not sure why this is now invalid, as its a legitimate 
issue I've been experiencing...

its a bit messy as of now, but heres the whole source code for my project.

#define BTN1 4   // GPIO definitions in Arduino - not physical pins
#define BTN2 5
#define SW1 8
#define SW2 9
#define SW3 10
#define SPK 11
#define AUD 7
const int led[4]={2,12,13,0}; // (2,3,12,13,0,6) with all LEDS onboard.

byte inputMode = 0x00;  // All input (buttons and switches) states stored here

byte counter = 0;
byte counterB = 0;
boolean readingA;
boolean readingB;
boolean currentStateA = HIGH;
boolean currentStateB = HIGH; // the debounced input value

long time = 0;
int debounceCount = 10;
byte randomLed = 0;

void setup() {

  for (byte i = 0; i < 3; i = i + 1) {  // Array of LEDS set to outputs
    pinMode(led[i], OUTPUT);
  }

  pinMode(BTN2,INPUT_PULLUP);  // Buttons, switches inputs pulled HIGH with internal pullup resistors
  pinMode(BTN1,INPUT_PULLUP);
  pinMode(SW1,INPUT_PULLUP);
  pinMode(SW2,INPUT_PULLUP);
  pinMode(SW3,INPUT_PULLUP);

  pinMode(SPK,OUTPUT);     // Speaker and audio jacks set to outputs
  pinMode(AUD,OUTPUT);
}

void loop() {

  if(millis() != time)
  {
    readingA = digitalRead(BTN1);
    readingB = digitalRead(BTN2);

    if(readingA == currentStateA && counter > 0)
    {
      counter--;
    }
    if(readingA != currentStateA)
    {
       counter++; 
    }

    if(readingB == currentStateB && counterB > 0)
    {
      counterB--;
    }
    if(readingB != currentStateB)
    {
       counterB++; 
    }

  if(counter >= debounceCount){    
    if(readingA == LOW){
      counter = 0;
      currentStateA = readingA;
      if(digitalRead(SW1) == LOW){
        if(digitalRead(SW2) == LOW){
          if(digitalRead(SW3) == LOW){
            tick();
          }else {
            tick();
          }
        }else {
          if(digitalRead(SW3) == LOW) {
            tick();
            highTone();
          }else {
            tick();
            randomTone();
          }
        }   
      }
      else {
        if(digitalRead(SW2) == LOW) {
          if(digitalRead(SW3) == LOW) {
            tick();
            pulseLed(1);
          }else {
            tick();
            randomLight();
          }
        }else {
          if(digitalRead(SW3) == LOW) {
            tick();
            toneLed(1,1);
          }else{
            tick();
            toneLed(randomLed, (randomLed %2) );
          }
        }
      }
    }

  if(counterB >= debounceCount){
    if(readingB == LOW){
      counterB = 0;
      currentStateB = readingB;
      if(digitalRead(SW1) == LOW){
        if(digitalRead(SW2) == LOW){
          if(digitalRead(SW3) == LOW){
            tick();
            tick();
          }else {
            tick();
            tick();
          }
        }else {
          if(digitalRead(SW3) == LOW) {
            tick();
            tick();
            midTone();
          }else {
            tick();
            tick();
            randomTone();
          }
        }   
      }
      else {
        if(digitalRead(SW2) == LOW) {
          if(digitalRead(SW3) == LOW) {
            tick();
            tick();
            pulseLed(2);
          }else {
            tick();
            tick();
            randomLight();
          }
        }else {
          if(digitalRead(SW3) == LOW) {
            tick();
            tick();
            toneLed(2,0);
          }else{
            tick();
            tick();
            toneLed(randomLed, (randomLed %2) );
          }
        }
      }
    }
  }
    time = millis();
    randomLed = time%4;
    if(randomLed == 2){  // random RED Leds only
      randomLed = 1;
    }
  }
  } 
}

void onOff(byte pin, int fallDelay, int postDelay) {  // function for digital 
outs
    digitalWrite(pin, HIGH);
    delay(fallDelay);
    digitalWrite(pin, LOW);
    delay(postDelay);
}

void randomLight() {
  onOff(led[randomLed],750,10);
}

void pulseLed(byte ledPin) {
  onOff(led[ledPin],750,10);
}

void toneLed(byte pinny, boolean lowhigh ) {
  digitalWrite(led[pinny],HIGH);
  if(lowhigh == LOW) {
    midTone();
  } else {
    highTone();
  }
  digitalWrite(led[pinny],LOW);
}

void highTone() {
  for (byte thisPin = 150; thisPin >= 10; thisPin--) { 
    onOff(SPK,1,1);
  }
}

void midTone() {
  for (byte thisPin = 100; thisPin >= 10; thisPin--) { 
    onOff(SPK,1,2);
  }
}

void randomTone() {
  randomLed /= 2;
  if(randomLed == 0) {
    midTone();
  } else {
    highTone();
  }
}

void tick() {
  digitalWrite(AUD,HIGH);
  delayMicroseconds(100);
  digitalWrite(AUD,LOW);
}

Original comment by hatchina...@gmail.com on 2 Dec 2013 at 10:09

GoogleCodeExporter commented 9 years ago
Do you have resistors with those LEDs?

Original comment by arduino....@gmail.com on 3 Dec 2013 at 12:26