Go Down

Topic: Problem calling the TimerOne library from my Charlieplex library (Read 570 times) previous topic - next topic

nikberry

This is Charlieplex.cpp (I have removed most of the code):
Code: [Select]
#include "Arduino.h"
#include "Charlieplex.h"

Charlieplex::Charlieplex(char* p, char n)
{

  CharlieIntensity = 0;
}

// Equivalent to digitalWrite, but for a virtual pin
void Charlieplex::wled(int p, char v)
{
  CharlieMode[p] = v;
}

// Equivalent to digitalRead, but for a virtual pin
byte Charlieplex::rled(int p)
{
  return CharlieMode[p];
}

// Turns off all LEDS
void Charlieplex::reset()
{
  int i;
  for(i = 0; i < CharlieNum * 2; i++) CharlieMode[i] = LOW;
}

// Turns on all LEDS
void Charlieplex::set()
{
  int i;
  for(i = 0; i < CharlieNum * 2; i++) CharlieMode[i] = HIGH;
}


void Charlieplex::intensity(unsigned char v)
{
  CharlieIntensity = 7 - v;
}

// Starts Charlieplex, with interval p microseconds between updates
// (p * 1-8) if using intensity
void Charlieplex::start(int p)
{
  Timer1.initialize(400);
  Timer1.attachInterrupt(IntrCharlieplex);
}

// Stops Charlieplex
void Charlieplex::stop()
{
  Timer1.stop();
}

// Interrupt routine, not called by user
void Charlieplex::IntrCharlieplex()
{

}



This is Charlieplex.h:
Code: [Select]
#ifndef CHARLIEPLEX_h
#define CHARLIEPLEX_h
#if defined(ARDUINO) && ARDUINO >= 100
  #include "Arduino.h"
#else
  #include "WProgram.h"
#endif

#include <TimerOne.h>

class Charlieplex {

  public:
    Charlieplex(char *p, char n);
    void wled(int p, char v);
    byte rled(int p);
    void reset();
    void set();
    void intensity(unsigned char v);
    void start(int p);
    void stop();

  private:
    void IntrCharlieplex();

    int CharlieCurrent;
    byte CharlieNum;
    int CharlieState;
    byte CharlieIntensity;
    byte CharliePins[20];
    byte CharliePairs[380][2];
    byte CharlieMode[380];
};

#endif



And this is the sketch:
Code: [Select]

#include <Charlieplex.h>


// Array of pin numbers
char pins[3] = { 11, 12, 13 };

Charlieplex charlieplex(pins, 3);
 
void setup()
{
  char i;


  // If using intensity, periods of > about 400
  // will cause the LEDS to flicker
  charlieplex.start(400);
  for(i = 0; i < 8; i++) {
    // 0 = dim, 7 = full on
    charlieplex.intensity(i);
    charlieplex.set();
    delay(1000);
    charlieplex.reset();
    delay(1000);
  }
  charlieplex.intensity(7);
}

char val;

void loop()
{
  int i;
  charlieplex.rled(3);
  for(i = 0; i < (3 * 2); i++) charlieplex.wled(i, (val >> i) & 1);
  val++;
  if(val >= 60) val = 0;
  delay(1000);
}


The error I get is:

H:\My Documents\Arduino\libraries\Charlieplex\Charlieplex.cpp: In member function 'void Charlieplex::start(int)':
H:\My Documents\Arduino\libraries\Charlieplex\Charlieplex.cpp:60: error: 'Timer1' was not declared in this scope
H:\My Documents\Arduino\libraries\Charlieplex\Charlieplex.cpp: In member function 'void Charlieplex::stop()':
H:\My Documents\Arduino\libraries\Charlieplex\Charlieplex.cpp:67: error: 'Timer1' was not declared in this scope

I can't work out how to fix this.  :smiley-sweat:

PaulS

Quote
I can't work out how to fix this.

The same way everyone else does. Quit trying to hide the use of a library from the sketch. Any library used MUST be included in the sketch, too.

nikberry

Thanks. That fixed it - gave me another error, but there you go.

PaulS

Quote
gave me another error, but there you go.

I wonder where you could help on that one.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy