Pages: [1]   Go Down
Author Topic: One example works from the BiColor LED set, the other doesn't.  (Read 1164 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 56
Eureka does not mean what you think.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

West Yorkshire, UK
Offline Offline
Edison Member
*
Karma: 44
Posts: 1375
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 56
Eureka does not mean what you think.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

The Netherlands
Offline Offline
Edison Member
*
Karma: 50
Posts: 1657
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 56
Eureka does not mean what you think.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

West Yorkshire, UK
Offline Offline
Edison Member
*
Karma: 44
Posts: 1375
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: August 10, 2013, 02:20:22 am by PaulRB » Logged

Leeds, UK
Offline Offline
Edison Member
*
Karma: 80
Posts: 1726
Once the magic blue smoke is released, it won't go back in!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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 - downloaded 20 times.)
Logged

~Tom~

Earth (I think)
Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Pages: [1]   Go Up
Jump to: