Go Down

Topic: Binary counter with 16 Leds (Read 962 times) previous topic - next topic

Grumpy_Mike

Code: [Select]

void display(unsigned int numberToDisplay){
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, numberToDisplay % 256);  lower byte
    shiftOut(dataPin, clockPin, MSBFIRST, numberToDisplay / 256);  higher byte
    digitalWrite(latchPin, HIGH);
}

// then use
   display(43690);

JimiH

Thanks Mike I'll give that a go.

Geoff

JimiH

Wow this doesn't want to go in??

I keep getting a
Code: [Select]
"core.a(main.cpp.o): In function `main':
C:\Program Files\ARDUINO\arduino-0022\hardware\arduino\cores\arduino/main.cpp:10: undefined reference to `loop'


Cant see where its gone wrong?

I have read you right Mike Void (display) instead of Void (loop)?
Code: [Select]
//**************************************************************//
//  Name    : shiftOutCode, Hello World                               
//  Author  : Carlyn Maw,Tom Igoe, David A. Mellis
//  Date    : 25 Oct, 2006   
//  Modified: 23 Mar 2010                                 
//  Version : 2.0                                             
//  Notes   : Code for using a 74HC595 Shift Register           //
//          : Display specified value                         
//****************************************************************

//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;


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);
  Serial.println("reset");
}

void display(unsigned int numberToDisplay){
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, numberToDisplay % 256);  //lower byte
    shiftOut(dataPin, clockPin, MSBFIRST, numberToDisplay / 256); // higher byte
    digitalWrite(latchPin, HIGH);
     display(43690);
}


Thanks

Geoff

Grumpy_Mike

Quote

I have read you right Mike Void (display) instead of Void (loop)?



No you always need a loop, you need the display as well, and you call it anywhere you want. Here I have put it in the setup();


Code: [Select]
//**************************************************************//
//  Name    : shiftOutCode, Hello World                               
//  Author  : Carlyn Maw,Tom Igoe, David A. Mellis
//  Date    : 25 Oct, 2006   
//  Modified: 23 Mar 2010                                 
//  Version : 2.0                                             
//  Notes   : Code for using a 74HC595 Shift Register           //
//          : Display specified value                         
//****************************************************************

//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;


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);
  Serial.println("reset");
       display(43690);
}

void loop(){
}

void display(unsigned int numberToDisplay){
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, numberToDisplay % 256);  //lower byte
    shiftOut(dataPin, clockPin, MSBFIRST, numberToDisplay / 256); // higher byte
    digitalWrite(latchPin, HIGH);
}

JimiH

Thanks Mike, still learning only had it a week  :smiley-red:

Geoff

Go Up