Hello, I am writing my first library. I would like to separate the "patterns" from (https://github.com/adafruit/LPD8806/blob/master/examples/LEDbeltKit_alt/LEDbeltKit_alt.pde) I tried to follow(http://arduino.cc/en/Hacking/LibraryTutorialCcccc). But to no avail. Where am I going wrong? Thanks in advance!
patternsSketch:28: error: 'Patterns' was not declared in this scope
//Patterns.cpp
#include "Arduino.h"
#include "Patterns.h"
void Patterns::renderEffect00(byte idx) {
if(fxVars[idx][0] == 0) {
byte *ptr = &imgData[idx][0],
r = random(256), g = random(256), b = random(256);
for(int i=0; i<numPixels; i++) {
*ptr++ = r; *ptr++ = g; *ptr++ = b;
}
fxVars[idx][0] = 1; // Effect initialized
}
}
}
//Patterns.h
#ifndef Patterns_h
#define Patterns_h
#include <Arduino.h>
class Patterns
{
public:
void renderEffect00();
private:
};
#endif
//slightly condensed for space.
//I added the lines with: **********************
#include <patterns.h>//*************
#include <avr/pgmspace.h>
#include "SPI.h"
#include "LPD8806.h"
#include "TimerOne.h"
const int numPixels = 32;
LPD8806 strip = LPD8806(numPixels);
byte imgData[2][numPixels * 3], // Data for 2 strips worth of imagery
alphaMask[numPixels], // Alpha channel for compositing images
backImgIdx = 0, // Index of 'back' image (always 0 or 1)
fxIdx[3]; // Effect # for back & front images + alpha
int fxVars[3][50], // Effect instance variables (explained later)
tCounter = -1, // Countdown to next transition
transitionTime; // Duration (in frames) of current transition
// function prototypes, leave these be :)
void renderEffect00(byte idx);
void renderEffect01(byte idx);
void renderEffect02(byte idx);
void renderEffect03(byte idx);
void renderAlpha00(void);
void renderAlpha01(void);
void renderAlpha02(void);
void renderAlpha03(void);
void callback();
byte gamma(byte x);
long hsv2rgb(long h, byte s, byte v);
char fixSin(int angle);
char fixCos(int angle);
void (*renderEffect[])(byte) = {
Patterns.renderEffect00(),
//renderEffect00,**********************
renderEffect01,
renderEffect02,
renderEffect03 },
(*renderAlpha[])(void) = {
renderAlpha00,
renderAlpha01,
renderAlpha02 };
// ---------------------------------------------------------------------------
void setup() {
strip.begin();
randomSeed(analogRead(0));
memset(imgData, 0, sizeof(imgData)); // Clear image data
fxVars[backImgIdx][0] = 1; // Mark back image as initialized
Timer1.initialize();
Timer1.attachInterrupt(callback, 1000000 / 60); // 60 frames/second
}
void loop() {
// Do nothing. All the work happens in the callback() function below,
// but we still need loop() here to keep the compiler happy.
}
void callback() {
strip.show();
byte frontImgIdx = 1 - backImgIdx,
*backPtr = &imgData[backImgIdx][0],
r, g, b;
int i;
(*renderEffect[fxIdx[backImgIdx]])(backImgIdx);
if(tCounter > 0) {
// Transition in progress
byte *frontPtr = &imgData[frontImgIdx][0];
int alpha, inv;
// Render front image and alpha mask based on current effect indices...
(*renderEffect[fxIdx[frontImgIdx]])(frontImgIdx);
(*renderAlpha[fxIdx[2]])();
// ...then composite front over back:
for(i=0; i<numPixels; i++) {
alpha = alphaMask[i] + 1; // 1-256 (allows shift rather than divide)
inv = 257 - alpha; // 1-256 (ditto)
r = gamma((*frontPtr++ * alpha + *backPtr++ * inv) >> 8);
g = gamma((*frontPtr++ * alpha + *backPtr++ * inv) >> 8);
b = gamma((*frontPtr++ * alpha + *backPtr++ * inv) >> 8);
strip.setPixelColor(i, r, g, b);
}
} else {
for(i=0; i<numPixels; i++) {
// See note above re: r, g, b vars.
r = gamma(*backPtr++);
g = gamma(*backPtr++);
b = gamma(*backPtr++);
strip.setPixelColor(i, r, g, b);
}
}
tCounter++;
if(tCounter == 0) { // Transition start
// Randomly pick next image effect and alpha effect indices:
fxIdx[frontImgIdx] = random((sizeof(renderEffect) / sizeof(renderEffect[0])));
fxIdx[2] = random((sizeof(renderAlpha) / sizeof(renderAlpha[0])));
transitionTime = random(30, 181); // 0.5 to 3 second transitions
fxVars[frontImgIdx][0] = 0; // Effect not yet initialized
fxVars[2][0] = 0; // Transition not yet initialized
} else if(tCounter >= transitionTime) { // End transition
fxIdx[backImgIdx] = fxIdx[frontImgIdx]; // Move front effect index to back
backImgIdx = 1 - backImgIdx; // Invert back index
tCounter = -120 - random(240); // Hold image 2 to 6 seconds
}
}
//**********************
//*******Put this in to Patterns.h and Patterns.cpp
//***********************
/*
*****void renderEffect00(byte idx) {
***** // Only needs to be rendered once, when effect is initialized:
***** if(fxVars[idx][0] == 0) {
***** byte *ptr = &imgData[idx][0],
***** r = random(256), g = random(256), b = random(256);
***** for(int i=0; i<numPixels; i++) {
***** *ptr++ = r; *ptr++ = g; *ptr++ = b;
***** }
***** fxVars[idx][0] = 1; // Effect initialized
***** }
*****}
*/
//*************
//********rest of file removed to save space. view original work @:
//******** https://raw.github.com/adafruit/LPD8806/master/examples/LEDbeltKit_alt/LEDbeltKit_alt.pde