Using Shift Registers & getting Exit Status 1 Error

I am new to programming and I am trying to light up rows of LEDs This is the code I am using and the error message (copy & pasted)...

exit status 1 Error compiling for board Arduino/Genuino Uno.

The code has no other errors.... I think. :confused:

#ifndef MultiShiftRegister_h
#define MultiShiftRegister_h

#if ARDUINO >= 100
#include "Arduino.h" 
#else
#include "WProgram.h"
#endif

class MultiShiftRegister {
    int m_latchPin, m_clockPin, m_dataPin, m_totalOutputPins, m_totalShiftRegisters;
    int* m_data;
  public:
    MultiShiftRegister (int, int, int, int);
    ~MultiShiftRegister();
    void set_shift(int);
    void set(int);
    void clear_shift(int);
    void clear(int);
    void shift();
  private:
    int getRegisterPin(int);
    int getRegisterNumber(int);
};

#endif


int latchPin  = 8;
int clockPin = 12;
int dataPin = 11;


int numberOfRegisters = 2;



MultiShiftRegister msr (numberOfRegisters , latchPin, clockPin, dataPin); 

void setup() {
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
}

void loop() {
 
  msr.set(5);



  msr.shift();

  delay(1000);

  
  msr.clear(5);
  msr.shift();

  delay(1000);

 
 
  msr.set(12); 
  msr.shift(); 
  delay(1000);
  msr.clear(12); 
  msr.shift(); 

  delay(1000);

 
  msr.set_shift(14);
  delay(1000);
  msr.clear_shift(14);

  delay(1000); 


  msr.set_shift(5);
  msr.set_shift(12);
  delay(1000);
  msr.clear_shift(5);
  msr.clear_shift(12);

  delay(1000);


  msr.set(5);
  msr.set(12);
  msr.shift();
  delay(1000);
  msr.clear(5);
  msr.clear(12);
  msr.shift();

  delay(1000);
}

Please go read the forum guide in the sticky post. That will tell you how to post code correctly on the forum. Then please modify your post above and fix it. The error message you told us gives no clue what the problem could be. Please post all the messages, also using code tags. There is a button on the ide that will copy them all for you so you can paste them between the code tags in your post.

The "exit status 1" is the last message shown in the event of a failed compile - the exit status is how the compiler tells the build scripts that it failed. Before that occurs, it will print information on the error(s) it encountered -
scroll up and look at them.

There are no lines of code highlighted in red. I do not see any other errors. If I have a bad or wrong connection on the bread board will this cause an errors?

When you encounter an error you‚Äôll see a button on the right side of the orange bar ‚ÄúCopy error messages‚ÄĚ. Click that button. Paste the error in a message here USING CODE TAGS (</> button on the toolbar).

Haueter:
If I have a bad or wrong connection on the bread board will this cause an errors?

No. This error is caused by a failure to compile your code. It has absolutely nothing to do with the hardware. You would get the same error even if you didn’t have the Arduino board plugged into your computer.

@Haueter, expand the box at the bottom of the IDE. You will see a bunch of lines like this in red:

C:\Users\CROSSR~1.CRO\AppData\Local\Temp\ccpywnD3.ltrans0.ltrans.o: In function `loop':


C:\Users\CrossRoadsFencing.CrossRoads\Documents\ArduinoStuff\Forum discussion designs\sketch_sep27a/sketch_sep27a.ino:51: undefined reference to `MultiShiftRegister::set(int)'


C:\Users\CrossRoadsFencing.CrossRoads\Documents\ArduinoStuff\Forum discussion designs\sketch_sep27a/sketch_sep27a.ino:55: undefined reference to `MultiShiftRegister::shift()'


C:\Users\CrossRoadsFencing.CrossRoads\Documents\ArduinoStuff\Forum discussion designs\sketch_sep27a/sketch_sep27a.ino:60: undefined reference to `MultiShiftRegister::clear(int)'


C:\Users\CrossRoadsFencing.CrossRoads\Documents\ArduinoStuff\Forum discussion designs\sketch_sep27a/sketch_sep27a.ino:61: undefined reference to `MultiShiftRegister::shift()'

So I'd suggest there is something going on with 'MultiShiftRegister' that needs fixing. If you select File:Preferences, and turn on Line Numbers, than the first error is on line 51:

msr.set(5);

which is the first time the class is used. Perhaps not enough values are being called out?

Error Message.

Arduino: 1.8.6 Hourly Build 2018/08/20 05:33 (Windows 7), Board: "Arduino/Genuino Uno"

C:\Users\HAUETE~1\AppData\Local\Temp\ccirn0G0.ltrans0.ltrans.o: In function `loop':

C:\Users\haueter14\Documents\Arduino\simple_blink/simple_blink.ino:48: undefined reference to `MultiShiftRegister::set(int)'

C:\Users\haueter14\Documents\Arduino\simple_blink/simple_blink.ino:52: undefined reference to `MultiShiftRegister::shift()'

C:\Users\haueter14\Documents\Arduino\simple_blink/simple_blink.ino:57: undefined reference to `MultiShiftRegister::clear(int)'

C:\Users\haueter14\Documents\Arduino\simple_blink/simple_blink.ino:58: undefined reference to `MultiShiftRegister::shift()'

C:\Users\haueter14\Documents\Arduino\simple_blink/simple_blink.ino:64: undefined reference to `MultiShiftRegister::set(int)'

C:\Users\haueter14\Documents\Arduino\simple_blink/simple_blink.ino:65: undefined reference to `MultiShiftRegister::shift()'

C:\Users\haueter14\Documents\Arduino\simple_blink/simple_blink.ino:67: undefined reference to `MultiShiftRegister::clear(int)'

C:\Users\haueter14\Documents\Arduino\simple_blink/simple_blink.ino:68: undefined reference to `MultiShiftRegister::shift()'

C:\Users\haueter14\Documents\Arduino\simple_blink/simple_blink.ino:73: undefined reference to `MultiShiftRegister::set_shift(int)'

C:\Users\haueter14\Documents\Arduino\simple_blink/simple_blink.ino:75: undefined reference to `MultiShiftRegister::clear_shift(int)'

C:\Users\haueter14\Documents\Arduino\simple_blink/simple_blink.ino:80: undefined reference to `MultiShiftRegister::set_shift(int)'

C:\Users\haueter14\Documents\Arduino\simple_blink/simple_blink.ino:81: undefined reference to `MultiShiftRegister::set_shift(int)'

C:\Users\haueter14\Documents\Arduino\simple_blink/simple_blink.ino:83: undefined reference to `MultiShiftRegister::clear_shift(int)'

C:\Users\haueter14\Documents\Arduino\simple_blink/simple_blink.ino:84: undefined reference to `MultiShiftRegister::clear_shift(int)'

C:\Users\haueter14\Documents\Arduino\simple_blink/simple_blink.ino:89: undefined reference to `MultiShiftRegister::set(int)'

C:\Users\haueter14\Documents\Arduino\simple_blink/simple_blink.ino:90: undefined reference to `MultiShiftRegister::set(int)'

C:\Users\haueter14\Documents\Arduino\simple_blink/simple_blink.ino:91: undefined reference to `MultiShiftRegister::shift()'

C:\Users\haueter14\Documents\Arduino\simple_blink/simple_blink.ino:93: undefined reference to `MultiShiftRegister::clear(int)'

C:\Users\haueter14\Documents\Arduino\simple_blink/simple_blink.ino:94: undefined reference to `MultiShiftRegister::clear(int)'

C:\Users\haueter14\Documents\Arduino\simple_blink/simple_blink.ino:95: undefined reference to `MultiShiftRegister::shift()'

C:\Users\HAUETE~1\AppData\Local\Temp\ccirn0G0.ltrans0.ltrans.o: In function `__static_initialization_and_destruction_0':

C:\Users\haueter14\Documents\Arduino\simple_blink/simple_blink.ino:38: undefined reference to `MultiShiftRegister::MultiShiftRegister(int, int, int, int)'

C:\Users\HAUETE~1\AppData\Local\Temp\ccirn0G0.ltrans0.ltrans.o: In function `_GLOBAL__sub_D_latchPin':

C:\Users\haueter14\Documents\Arduino\simple_blink/simple_blink.ino:38: undefined reference to `MultiShiftRegister::~MultiShiftRegister()'

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Arduino/Genuino Uno.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Is this because the program can not find the files on my computer?

The errors are exactly correct. You are trying to call functions that are declared in the MultiShiftRegister class but aren't defined anywhere in your code.

I suspect you didn't write this code. Please post a link to where you found the code.

Which files? You barely point to them :wink:

Go back to the place you ripped that (part of a) library from and look for examples on how to

  1. Download that library
  2. Use that library

I did find a code that would work for what I need it to do. I have zero coding experience.

here is the link.

You only pasted the header file into your sketch. I have no clue why you thought that was a good idea. You would have needed to paste the contents of MultiShiftRegister.cpp also. However, that’s not how it’s intended to be used. This is a library. Libraries provide a convenient way to share useful code between projects. You install the library and then when you add a #include directive for the library’s header file to your sketch, you will have access to all the library’s functions in that sketch:

#include <MultiShiftRegister.h>

Here’s how you install the library:

  • Go to the home page for the library‚Äôs repository: https://github.com/maketronica/MultiShiftRegister
  • Click ‚ÄúClone or download‚ÄĚ.
  • Click ‚ÄúDownload ZIP‚ÄĚ.
  • (In the Arduino IDE) Sketch > Include Library > Add .ZIP Library‚Ķ > select the downloaded file > Open

After that, delete the screwy modified sketch you hacked together and go back to using the unmodified example sketch provided by the library author:
https://github.com/maketronica/MultiShiftRegister#use

General information on installing Arduino Libraries:

MultiShiftRegister only handles multiple shift registers for you. Changes nothing about the Q7' pin though...

I just noticed the dumbbell library author used the wrong comment syntax in that example sketch. Here it is fixed:

#include <MultiShiftRegister.h>

int latchPin  = 8;
int clockPin = 12;
int dataPin = 11;

// How many 8 bit shift registers we're talking to.
// Two 8 bit registers can host 16 individually
// addressable binary outputs.
int numberOfRegisters = 2;

// Setup group of shift registers and name it `msr`.
// All outputs are initialized to low/off.
MultiShiftRegister msr (numberOfRegisters , latchPin, clockPin, dataPin); 

void setup() {
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
}

void loop() {
  // Prepare to turn on pin 5.
  // Pin 5 is still low/off.
  msr.set(5);

  // Shift data out, with appropriate latches.
  // Pin 5 is now high/on.
  msr.shift();

  delay(1000);

  // Turn pin 5 back off.
  msr.clear(5);
  msr.shift();

  delay(1000);

  // Turn pin 12 (4th output on the second shift register)
  // on and off again.
  msr.set(12); 
  msr.shift(); 
  delay(1000);
  msr.clear(12); 
  msr.shift(); 

  delay(1000);

  // This set and shift business is getting repetitive.
  // Let's do it in one line instead.
  msr.set_shift(14);
  delay(1000);
  msr.clear_shift(14);

  delay(1000);

  // But wait, this is inefficient. It doesn't actually turn
  // outputs 5 and 12 on simultaneously. There is a very tiny delay
  // as it shifts output 5 before setting output 12. This may or
  // may not be a problem, depending on your application.
  msr.set_shift(5);
  msr.set_shift(12);
  delay(1000);
  msr.clear_shift(5);
  msr.clear_shift(12);

  delay(1000);

  // So, consider doing this to prepare both outputs before shifting them.
  msr.set(5);
  msr.set(12);
  msr.shift();
  delay(1000);
  msr.clear(5);
  msr.clear(12);
  msr.shift();

  delay(1000);
}

And my pull request:
https://github.com/maketronica/MultiShiftRegister/pull/2

If only that was the only weird thing...

New error

Arduino: 1.8.6 Hourly Build 2018/08/20 05:33 (Windows 7), Board: "Arduino/Genuino Uno"

Sketch uses 2310 bytes (7%) of program storage space. Maximum is 32256 bytes.
Global variables use 31 bytes (1%) of dynamic memory, leaving 2017 bytes for local variables. Maximum is 2048 bytes.
avrdude: ser_open(): can't open device "\\.\COM1": The system cannot find the file specified.


Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

You need to select the COM port of your board from the Tools > Port menu.

Haueter:

Arduino: 1.8.6 Hourly Build 2018/08/20 05:33

The hourly build of the Arduino IDE is only intended to be used for beta testing. For normal usage, you should be using a production release version of the Arduino IDE. And if you are going to use the hourly build, at least use the latest version, not one that's >6 weeks outdated.