Go Down

Topic: One example works from the BiColor LED set, the other doesn't. (Read 1 time) previous topic - next topic

doctorwho8

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:
Code: [Select]

\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:

Quote

  if (lb != led.lastBlink) {


I confess I am lost here.

PaulRB

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

doctorwho8


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


Hello!
It gets described here http://playground.arduino.cc//Code/BiColorLED and can be downloaded from places shown there.

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.
Have a look at "blink without delay".
Did you connect the grounds ?
Je kunt hier ook in het Nederlands terecht: http://arduino.cc/forum/index.php/board,77.0.html

doctorwho8


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:
Code: [Select]

#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.

PaulRB

#5
Aug 10, 2013, 09:12 am Last Edit: Aug 10, 2013, 09:20 am by PaulRB Reason: 1
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

Tom Carpenter

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.
~Tom~

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.

Go Up