Go Down

Topic: Chasing Ring LED Code Bug (Read 764 times) previous topic - next topic

sni9er

Morning Folks

Hopefully someone brighter than me can work out this brick wall I've come against

The Issue i have is when "i" gets to a count of 9 Pin 0 mysteriously goes low the rest of the sequence loops flawlessly and at the speed i'll be going it's hardly noticeable BUT i would like to understand wat the heck is actually going on to cause it

I've had a fun (but at time stressful time) making  my LED Array

It consists of 32 LEDs in a ring chasing with 16 LEDs on and 16 LEDs Off (like a chasing half circle if you can imagine)

I'm using Bildr's Shift Register Library (Shifter.h - http://bildr.org/2011/08/74hc595-breakout-arduino/)


I have more work to do to expand in the code and control another 32 LEDs to do another function of my array (ergo more shifters than being used currently in the code)



Code: [Select]
#include <Shifter.h>

#define SER_Pin 4 //SER_IN
#define RCLK_Pin 5 //L_CLOCK
#define SRCLK_Pin 6 //CLOCK

#define NUM_REGISTERS 9 //how many registers are in the chain


//initaize shifter using the Shifter library
Shifter shifter(SER_Pin, RCLK_Pin, SRCLK_Pin, NUM_REGISTERS);

void setup(){
}

int del = 15;

void loop(){

for (int i=0; i <= 31; i++)
  {
  shifter.setPin(i-16, LOW);
  shifter.setPin(i, HIGH);
  shifter.setPin(i+16, LOW);
  delay(del);
  shifter.write();
 

 }
}


One thing I tried was to insert a line that said:

Code: [Select]
shifter.setPin(i-9, HIGH);

however then the mystery low signal jumps to i-11 then i-15 after inserting those (below) lines the speed of operation is being effected that is less desirable than the initial problem as i must have a smooth fast rotation

Code: [Select]
  shifter.setPin(i-9, HIGH);
  shifter.setPin(i-11, HIGH);
  shifter.setPin(i-14, HIGH);
  shifter.setPin(i-15, HIGH);



does anyone have any ideas how to nail this bug to the wall ?



runaway_pancake


Code: [Select]


#include <Shifter.h>
#define SER_Pin 4 //SER_IN
#define RCLK_Pin 3 //L_CLOCK
#define SRCLK_Pin 2 //CLOCK
#define NUM_REGISTERS 4 //how many registers are in the chain
Shifter shifter(SER_Pin, RCLK_Pin, SRCLK_Pin, NUM_REGISTERS);
byte head;
byte tail;
byte index;
void setup ()
{
  atInit();
  head = 15;
  tail = 0;
}
void loop ()
{
  for (index = 0; index < 32; index ++)
  {
    head ++:
    if (head > 31)
    {
      head = 0;
    }
    shifter.setPin(head,HIGH);
    shifter.setPin(tail,LOW);
    shiter.write();
    delay(200);
    tail ++;
    if (tail > 31)
    {
      tail = 0;
    }
  }
}
void atInit ()
{
  shifter.clear();
  for (index = 0; index < 16; index ++)
  {
    shifter.setPin(index, HIGH);
  }
  shifter.write();
}
"Who is like unto the beast? who is able to make war with him?"
When all else fails, check your wiring!

sni9er

Wow Thanks for that Runaway!

was there anything you spotted that caused my code to be bad ?

trying to read through yours to get a grip on how it works but it defo works thanks !!!

runaway_pancake

was there anything you spotted that caused my code to be bad ?

Things like
Code: [Select]

for (int i=0; i <= 31; i++)
  {
  shifter.setPin(i-16, LOW);

will result negative numbers (when i = 0, then i - 16 = -16 → not good)

So I just knocked it out the way that I saw it.
"Who is like unto the beast? who is able to make war with him?"
When all else fails, check your wiring!

sni9er

Things like
Code: [Select]

for (int i=0; i <= 31; i++)
  {
  shifter.setPin(i-16, LOW);

will result negative numbers (when i = 0, then i - 16 = -16 → not good)

So I just knocked it out the way that I saw it.

thank you very much!


Go Up