One example works from the BiColor LED set, the other doesn't.

Hello!
I am trying out the BiColor LED examples on an Arduino, and as it happens one of them does work. Naturally the one named in the example, BiColor does indeed work. However the one named Blink does not. It produces an error:

\Arduino\libraries\bicolor/BiColorLED.h: In function 'void loop()':
\Arduino\libraries\bicolor/BiColorLED.h:42: error: 'long unsigned int BiColorLED::lastBlink' is private
Blink:23: error: within this context
\Arduino\libraries\bicolor/BiColorLED.h:42: error: 'long unsigned int BiColorLED::blinkSpeed' is private
Blink:24: error: within this context
\Arduino\libraries\bicolor/BiColorLED.h:42: error: 'long unsigned int BiColorLED::lastBlink' is private
Blink:26: error: within this context
\Arduino\libraries\bicolor/BiColorLED.h:42: error: 'long unsigned int BiColorLED::lastBlink' is private
Blink:27: error: within this context

And the code that threw up that error message is:

if (lb != led.lastBlink) {

I confess I am lost here.

Hi, can you post the full code or a link to it please.

PaulRB:
Hi, can you post the full code or a link to it please.

Hello!
It gets described here Arduino Playground - HomePage and can be downloaded from places shown there.

That is not posting your code.
It takes you one single mistake to get error like these.
So linking to some instructions how to use or manipulate hardware will not tell anything about what is wrong with what you've got.

MAS3:
That is not posting your code.
It takes you one single mistake to get error like these.
So linking to some instructions how to use or manipulate hardware will not tell anything about what is wrong with what you've got.

Hello!
The gentleman wanted either my code, or a link to it. I figured that the best way to present it would be the playground location, who best describes it, but since you wanted to see the code I used:

#include <BiColorLED.h>

// Simple demo of blinking using BiColorLED library
// Requires v1.1 or greater
// (C) 2012 Wolfgang Faust

// To see the effects of this example, just plug a bi-color LED
// into pins 4 and 5, along with the appropriate resistors.

BiColorLED led=BiColorLED(4,5); // (pin 1, pin 2)
unsigned long lb; // Time the colour was last changed

void setup() {
  Serial.begin(9600);
  led.setColor(1);
  led.setColor2(2);
  led.setBlinkSpeed(1000);
}

void loop() {
  // led.drive() MUST be called for blinking (and yellow) to work.
  led.drive();
  if (lb != led.lastBlink) {
    Serial.print(led.blinkSpeed);
    Serial.print(":");
    Serial.println(led.lastBlink);
    lb=led.lastBlink;
  }
}

So that is the code that was presented. I haven't changed anything in it.

Seems to me there are errors in the example as published. Has anyone got it to work as-is?

The example code refers to the variables lastBlink and blinkSpeed that are part of the BiColorLED object, but the header says these are private, so can't be used from outside the object. A getBlinkSpeed function is provided which could be used, but no function to return the value of lastBlink.

I'm not an expert in how object-oriented code is supposed to be written in C/C++, but I thought the header file was supposed to tell the programmer using the object/class about the "published" interface (the parts exposed to the user) so I'm not sure why anything would appear in the header that is declared private?

Paul

Corrected header file attached.

Though I have to say this in the nicest possible way, while sure there is a library for every single task imaginable nowadays, for a task as simple as controlling two LEDs, surely you would learn a lot more if you tried to write some code yourself.

Literally all the library really does (In pseudo code) is:

if colour = red
red = high
green = low.
else if colour = green
red = low
green = high.
else
red = low
green = low.

BiColorLED.h (1.34 KB)

Hi, I'm the author of the BiColorLED library. Sorry to resurrect an old post, but I wanted to clear this up in case someone encounters this thread in the future.

The blinkSpeed and lastBlink variables should, in fact, be private; it's the example that's wrong. I left a bit of debugging code in by mistake when I released the library. I've put out a new version (1.3) which fixes the example.