Pages: [1]   Go Down
Author Topic: 14 to 16 LED's?  (Read 954 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi

Just finished construction this.

http://kimballhutchins.com/node/17

The author only had room for 14 LED's I have room for all 16 however only 14 LED's are performing?

Where in this code is it telling the arduino to only use 14 outs and not 16?

Code:
void backAndForthSplit(int numRepeat){
  while (numRepeat!=0){
    int left=1;
    int right=1;
    for (right=64;right>=1;right=right/2){
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, left);
      shiftOut(dataPin, clockPin, right);
      digitalWrite(latchPin, HIGH);
      left = 2*left;
      delay(time);

is it the 64?

Thanks

Geoff
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 597
Posts: 33314
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
is it the 64?
No that outputs 16 bits to the shift register. You will have to post the rest of the code.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Thanks its pretty long.

Code:
//**************************************************************//
//  Name    : LED Blink Patters                               
//  Author  : Kimball Hutchins
//  Date    : 7 July, 2010   
//  Modified:                                 
//  Version : 2.0                                             
//  Notes   :            //                           
//****************************************************************
 
//Pin connected to ST_CP of 74HC595
int latchPin = 8;
//Pin connected to SH_CP of 74HC595
int clockPin = 12;
////Pin connected to DS of 74HC595
int dataPin = 11;
 
int time = 250;
 
//Serial.println(val);
 
void setup() {
  //set pins to output so you can control the shift register
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  Serial.begin(9600);
}
 
void loop() {
 
 
  int left=1;
  int right=1;
 
 
    blinkAll_2Bytes(6,250);
    repeatFromOuter(6);
    backAndForthSplit(6);
    oneByOne(1,0,1);
    oneByOneReverse(1,0,1);
    negOneByOne(1,127,6);
    negOneByOneReverse(1,127,6);
      alternate(4);
 
 
}
 
 
void repeatFromOuter( int numRepeat){
  while (numRepeat!=0){
   int left=1;
   int right=1;
    for (right=64;right>=1;right=right/2){
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, left);
      shiftOut(dataPin, clockPin, right);
      digitalWrite(latchPin, HIGH);
      left = 2*left;
      delay(time);
    }
    numRepeat-=1;
  }
}
 
void backAndForthSplit(int numRepeat){
  while (numRepeat!=0){
    int left=1;
    int right=1;
    for (right=64;right>=1;right=right/2){
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, left);
      shiftOut(dataPin, clockPin, right);
      digitalWrite(latchPin, HIGH);
      left = 2*left;
      delay(time);
    }
 
    left=64;
    for (right=1;right<=64;right=right*2){
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, left);
      shiftOut(dataPin, clockPin, right);
      digitalWrite(latchPin, HIGH);
      left = left/2;
      delay(time);
    }
    numRepeat-=1;
  }
}   
 
void oneByOne(int left, int right, int numRepeat){
  while (numRepeat!=0){
    left=1;
    right=0;
    for (left=1;left<=64;left=left*2){
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, right);
      shiftOut(dataPin, clockPin, left);
      digitalWrite(latchPin, HIGH);
      delay(time);
    }
 
    left=1;
    right=0;
    for (left=1;left<=64;left=left*2){
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, left);
      shiftOut(dataPin, clockPin, right);
      digitalWrite(latchPin, HIGH);
      delay(time);
    }
    numRepeat-=1;
  }
}
 
void oneByOneReverse(int left, int right, int numRepeat){
  while (numRepeat!=0){
    for (left=64;left>=1;left=left/2){
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, left);
      shiftOut(dataPin, clockPin, right);
      digitalWrite(latchPin, HIGH);
      delay(time);
    }
 
    for (left=64;left>=1;left=left/2){
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, right);
      shiftOut(dataPin, clockPin, left);
      digitalWrite(latchPin, HIGH);
      delay(time);
    }
 
    numRepeat-=1;
  }

 
void negOneByOne(int left, int right, int numRepeat){
  while (numRepeat!=0){
    for (left=0;left<=6;left++){
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, right);
      shiftOut(dataPin, clockPin, (127-pow(2,left)));
      digitalWrite(latchPin, HIGH);
      delay(time);
    }
 
    right=127;
    for (left=0;left<=6;left++){
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, (127-pow(2,left)));
      shiftOut(dataPin, clockPin, right);
      digitalWrite(latchPin, HIGH);
      delay(time);
    }
 
    numRepeat-=1;
  }
}
 
void negOneByOneReverse(int left, int right, int numRepeat){
  while (numRepeat!=0){
    for (left=6;left>=0;left--){
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, (127-pow(2,left)));
      shiftOut(dataPin, clockPin, right);
      digitalWrite(latchPin, HIGH);
      delay(time);
    }
 
    right=127;
    for (left=6;left>=0;left--){
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, right);
      shiftOut(dataPin, clockPin, (127-pow(2,left)));
      digitalWrite(latchPin, HIGH);
      delay(time);
    }
 
    numRepeat-=1;
  }
}
 
 
void alternate(int numRepeat){
  while (numRepeat!=0){
//    0101010 = 42
//    1010101 = 85
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, 42);
    shiftOut(dataPin, clockPin, 85);
    digitalWrite(latchPin, HIGH);
    delay(time);
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, 85);
    shiftOut(dataPin, clockPin, 42);
    digitalWrite(latchPin, HIGH);
    delay(time);
 
    numRepeat-=1;
  }
}
 
 
// The following is from <a href="http://arduino.cc/en/Tutorial/ShftOut22" title="http://arduino.cc/en/Tutorial/ShftOut22">http://arduino.cc/en/Tutorial/ShftOut22</a> not me.
//
// the heart of the program
void shiftOut(int myDataPin, int myClockPin, byte myDataOut) {
  // This shifts 8 bits out MSB first,
  //on the rising edge of the clock,
  //clock idles low
 
  //internal function setup
  int i=0;
  int pinState;
  pinMode(myClockPin, OUTPUT);
  pinMode(myDataPin, OUTPUT);
 
  //clear everything out just in case to
  //prepare shift register for bit shifting
  digitalWrite(myDataPin, 0);
  digitalWrite(myClockPin, 0);
 
  //for each bit in the byte myDataOut�
  //NOTICE THAT WE ARE COUNTING DOWN in our for loop
  //This means that %00000001 or "1" will go through such
  //that it will be pin Q0 that lights.
  for (i=7; i>=0; i--)  {
    digitalWrite(myClockPin, 0);
 
    //if the value passed to myDataOut and a bitmask result
    // true then... so if we are at i=6 and our value is
    // %11010100 it would the code compares it to %01000000
    // and proceeds to set pinState to 1.
    if ( myDataOut & (1<<i) ) {
      pinState= 1;
    }
    else {
      pinState= 0;
    }
 
    //Sets the pin to HIGH or LOW depending on pinState
    digitalWrite(myDataPin, pinState);
    //register shifts bits on upstroke of clock pin 
    digitalWrite(myClockPin, 1);
    //zero the data pin after shift to prevent bleed through
    digitalWrite(myDataPin, 0);
  }
 
  //stop shifting
  digitalWrite(myClockPin, 0);
}
 
//blinks the whole register based on the number of times you want to
//blink "n" and the pause between them "d"
//starts with a moment of darkness to make sure the first blink
//has its full visual effect.
void blinkAll_2Bytes(int n, int d) {
  digitalWrite(latchPin, 0);
  shiftOut(dataPin, clockPin, 0);
  shiftOut(dataPin, clockPin, 0);
  digitalWrite(latchPin, 1);
  delay(200);
  for (int x = 0; x < n; x++) {
    digitalWrite(latchPin, 0);
    shiftOut(dataPin, clockPin, 255);
    shiftOut(dataPin, clockPin, 255);
    digitalWrite(latchPin, 1);
    delay(d);
    digitalWrite(latchPin, 0);
    shiftOut(dataPin, clockPin, 0);
    shiftOut(dataPin, clockPin, 0);
    digitalWrite(latchPin, 1);
    delay(d);
  }
}
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 518
Posts: 26344
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I think its  here:

void alternate(int numRepeat){
  while (numRepeat!=0){
//    0101010 = 42
//    1010101 = 85

only have 7 bits defined
change to B10101010 equal to decimal 170
& B01010101, and this actually still stays 85
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Thanks, dont think its that as the main code contains multiple patterns and that is just one.

Code:
blinkAll_2Bytes(6,250);
    repeatFromOuter(6);
    backAndForthSplit(6);
    oneByOne(1,0,1);
    oneByOneReverse(1,0,1);
    negOneByOne(1,127,6);
    negOneByOneReverse(1,127,6);
      alternate(4);

Then "BlinkAll_2Bytes" does light up all 16 but the rest only use 14.


I'll change it anyway in the code and see what happens.

Regards

Geoff
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Think I may of found it!

Code:
void negOneByOneReverse(int left, int right, int numRepeat){
  while (numRepeat!=0){
    for (left=6;left>=0;left--){
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, (127-pow(2,left)));
      shiftOut(dataPin, clockPin, right);
      digitalWrite(latchPin, HIGH);
      delay(time);
    }
 
    right=127;
    for (left=6;left>=0;left--){
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, right);
      shiftOut(dataPin, clockPin, (127-pow(2,left)));
      digitalWrite(latchPin, HIGH);
      delay(time);
    }
 
    numRepeat-=1;
  }
}

This line has 7 bytes ( 6 - 0)
Code:
for (left=6;left>=0;left--){

Should be

Code:
for (left=7;left>=0;left--){

I think

Geoff
Logged

Pages: [1]   Go Up
Jump to: