Problem with Libraries

Hi folks, first let me start by saying that I am very new to Arduino, and microcontrollers in general. I've played around with Picaxe for a few weeks and learned quite a bit, but now I feel like I'm starting all over, but that's ok, as I love to challenge myself :slight_smile: Just be advised I have NO formal training in programming.

I've recently taken up model building and my ultimate goal is to create a few simple programs to control LED lighting effects in Star Trek model ships, like ramping up and fading LEDs with button presses from a momentary switch and blinking LEDs on two outputs at different rates simultaneously.

Long story short, I've built myself a little Arduino shield to program attiny85s using the Arduino as an ISP. I found this "example sketch" here--> ( http://www.gammon.com.au/forum/?id=11411 ) There's also a Library zip file which I cannot get to work, nor will the "sketch" compile

// Example of flashing multiple LEDs at different rates without delays
// Author: Nick Gammon
// Date: 23 December 2012

#include <LedFlasher.h>

// set up some LEDs
LedFlasher floodLight (8, 200, 300);
LedFlasher shuttleBayDoors (9, 300, 600);
LedFlasher impulseEngine (10, 900, 100);
LedFlasher strobe (11, 500, 1000);
LedFlasher navigation (12, 1000, 2000);
LedFlasher torpedoes (13, 250, 500);

void setup() 
  {      
  floodLight.begin ();
  shuttleBayDoors.begin ();
  impulseEngine.begin ();
  strobe.begin ();
  navigation.begin ();
  torpedoes.begin ();
  }  // end of setup

void loop() 
  {
  // update lights
  floodLight.update ();
  shuttleBayDoors.update ();
  impulseEngine.update ();
  strobe.update ();
  navigation.update ();
  torpedoes.update ();
  
  
  // do other useful stuff here ...

 
  }  // end of loop

But I don't need all of that code, as I do not need to control that many LEDs, so I've modified it to suit my needs for the attiny85........

// set up some leds
#include LedFlasher strobe (2, 500, 70); // pin2 off for 500 mS, on for 70 mS
#include LedFlasher navigation (3, 1200, 1200); //pin 3 off for 1200 ms on for 1200 ms


void setup() 
  {      
  strobe.begin ();
  navigation.begin ();
  }  // end of setup

void loop() 
  {
  // update lights
  strobe.update ();
  navigation.update ();
  } //end of loop

Is it a major operation to transform that into a workable sketch???

It is not a major transformation but the code you have created will not even compile.

The #include directive is to include other files in your code. In this case the definitions from Nick's LedFlasher 'library'. So you will see his include is

#include <LedFlasher.h>

to insert the library file at this point in the code.

He then declares LedFlasher 'objects' with their own characteristics

LedFlasher floodLight (8, 200, 300);
LedFlasher shuttleBayDoors (9, 300, 600);

Clearly NIck is controlling the Starship Enterprise, but he has different objects for the different LED circuits that he wants to control.

On the other hand, your code seems to have mixed these two concepts up. Revisit and change the code to follow the pattern of the original. The rest of the code looks like NIck's original, so it should be ok.

It is not a major transformation but the code you have created will not even compile.

Hi Marco. Thank you for responding.

The problem is, Nick's "example" sketch will not compile either and I do not know how to write it on my own. I was just attempting to show you what part of the sketch that I need. In other words, I just want to blink two LEDs, one of them ON for 70ms, OFF for 500ms, the other one ON for 1200, OFF for 1200.

I unzipped the LedFlasher library file and copied the folder to My Documents/Arduino/Library. The LedFlasher library then shows up in the "Sketch--->Import Library-->Contributed" menu list, but when I try to select it, nothing is added to the sketch. It's strange though, because the cursor jumps back to the top of the page and the sketch moves down one line, like when you hit the Return key. Also, if I look under "Edit" after trying to import the library, the selection "undo addition" is available. Libraries usually include an example sketch, as they have an "example" sub-directory included in them, but the LedFlasher library does not, and as I said before, the example sketch he posted in the thread will not compile. If it would, I'm sure I could figure out how to modify to suit what I'm wanting to do, in other words, just trim off the fat that I don't want.

You will have a better chance with this:

#include <LedFlasher.h> 

// set up some leds
LedFlasher strobe (2, 500, 70); // pin2 off for 500 mS, on for 70 mS
LedFlasher navigation (3, 1200, 1200); //pin 3 off for 1200 ms on for 1200 ms

void setup() 
  {      
  strobe.begin ();
  navigation.begin ();
  }  // end of setup

void loop() 
  {
  // update lights
  strobe.update ();
  navigation.update ();
  } //end of loop

Not compiled but I am guessing it will work.

Contributed libraries are better installed in a libraries folder in your sketchbook folder, as this way they survive the updates to the IDE software. It should still work where you have placed it but beware when upgrades to the IDE happen, as you will have forgotten by then :slight_smile:

Contributed libraries are better installed in a libraries folder in your sketchbook folder, as this way they survive the updates to the IDE software. It should still work where you have placed it but beware when upgrades to the IDE happen, as you will have forgotten by then :slight_smile:

Hello again, Marco. I think you mis-understood. I DID install the LedFlasher library to the sketchbook-->Libraries folder, which is a sub-directory of My Documents-->Arduino (running Windows XP). The default arduino libraries folder is in an entirely different location, under C:\Program Files\Arduino\libraries.

I obviously need to read up on it a little more. I did read the page about libraries on the arduino web-site, but I still don't have a good understanding of how it works. When I try to import the LedFlasher library into the sketch, nothing happens, as I explained in my previous post. Even when I import an indigenous library, it just puts one or more of those ".h" files in the sketch and I don't understand what I'm supposed to do with that.

I know what you're thinking....and you're absolutely right, I'm totally raw at this. If perhaps you could explain it a little in layman's terms (and don't worry about sounding condescending, you're gonna have to talk down to me brotha). Or maybe you could point me to some more in-depth literature on the subject

Ok, all of that said, I copied and pasted the code you posted above into a new sketch, but I get compiling errors.....

ledflasher does not name a type
in function void setup....
strobe was not declared in this scope
navigation was not declared in this scope
in function void loop.....
same as above

Oh and by the way, thank you very much, Marco. I really appreciate your taking the time to try to help me.

'Libraries' in Arduino speak are not really libraries. They are more just bodies of code that get added into your code. The header file is the thing that triggers the code to get added, so when you say you want to add a library from the menu, it simply puts the header file there, which is what you say you see for those that are working.

btw, LEDflasher, ledflasher, LedFlasher are all unique names, so make sure we are using the right one in the code or you will et the error messages you report.

Try this - go to the library link below and pick any one of the libraries (say the LM35 one) and install it the way you have done with LedFlasher. Use one of the examples and see if you can compile that.

I downloaed and installed "MultiBlink v4, then loaded the example sketch and it compiled just fine. I might be able to modify that sketch to get what I want. It looks like it is designed to be modified.

About the libraries, does the code associated with the header file(s) get added to the sketch when you hit "Upload"? I understand what you mean about case SenSiTive file names, but the "LedFlasher" library still doesn't work and I haven't messed with any of the file names, I just copied and pasted the code into my sketch, then hit compile. Any idea why it's not working?

Code gets copied in at compile time, not when you paste the header file name. The header tells the IDE to add in the source file, amongst other things.

MultiBlink will do what you want but it is more complex. Could be easier to modify for you, though.

MultiBlink will do what you want but it is more complex. Could be easier to modify for you, though.

I guess I'll have to try to figure it out, since I can't get the LedFlasher library to work. Does it work for you?

LedFlasher or MultiBlink?

I wrote MB so it works for me, LedFlasher I have not tried.

Hi.

I had a similar problem, and I fix it.
The downloaded file possessed subfolders. For example:

Time.zip - He owned the Time and TimeAlarms folders.

When you add this zipfile by te IDE, a folder was created in my library directory with the name "Time". And when I tried to import this library in my sketch, was the same problem of robertgzzzt.

I solved the problem by adding the subfolders directly into the libraries directory.
Thus, the IDE created two contributed libraries for use: Time and TimeAlarms.
And when importing the Sketch, both functioned normally.

Hope this helps.
Regards from Brazil :slight_smile: