I’m trying to sort this bit of code, have googled but am struggling to see why it is not working.
I have a sketch that works fine. What I wanted to do is have the set up and part of the code in an #include file. (I'm new to this idea). Right now just working on one function.
Below I have posted the code, mostly stripped down from the original code.
I have created a Cube.h and Cube.cpp. When I call this code from my sketch I get this error.
“expected unqualified-id before '.' token”. I have done a bit of looking and appear that I have syntax error, but can’t fine it.
“expected unqualified-id before -Message found in GCC version 4.5.1 -check your syntax for missing, misplaced, or erroneous characters”
This is why my code is now reduced to just calling the function in Cube.cpp. I can't see it as a syntex error.
The error occurs at line 17 of the sketch. If I remark out line 17 the code complies.
I’ll appreciate any help in understanding what I’m doing wrong.
My Sketch
//The 8x8x12 RGB LED Cube
#include "Cube.h"
//****setup****
void setup() {
}//***end setup***
void loop() { //***start loop***
Cube.LED(1,1,1,2,2,2) //This is Line 17, error here.
}//***end loop***
Cube.h
//Updating Code for 8x8x12 layer LED RGB cube, data update and interrupt
#ifndef Cube_h
#define Cube_h
#include "Arduino.h"
class Cube {
public:
void LED(int Y, int X, int Z, byte red, byte green, byte blue);
byte red0[96], red1[96], red2[96], red3[96];
byte blue0[96], blue1[96], blue2[96], blue3[96];
byte green0[96], green1[96], green2[96], green3[96];
};
#endif
Cube.cpp
#include "Arduino.h"
#include "Cube.h"
void Cube::LED(int Y, int X, int Z, byte red, byte green, byte blue) { //****LED Routine
// First, check and make sure nothing went beyond the limits, just clamp things at either 0 or 15 for location, and 0 or 15 for brightness
if (Y < 0) Y= 0;
if (Y> 11) Y = 11;
if (X < 0) X = 0;
if (X > 7) X = 7;
if (Z < 0) Z = 0;
if (Z > 7) Z = 7;
if (red < 0) red = 0;
if (red > 15) red = 15;
if (green < 0) green = 0;
if (green > 15) green = 15;
if (blue < 0) blue = 0;
if (blue > 15) blue = 15;
//There are 768 LEDs in the cube, so when we write to level 2, column 5, row 4, that needs to be translated into a number from 0 to 767
int whichbyte = int(((Y * 64) + (X * 8) + Z) / 8);
// This next variable is the same thing as before, but here we don't divide by 8, so we get the LED number 0-767
int wholebyte = (Y* 64) + (X* 8) + Z;
//This is 4 bit color resolution, so each color contains 3 x 96 byte arrays.
//*** RED ***
bitWrite(red0[whichbyte], wholebyte - (8 * whichbyte), bitRead(red, 0));
bitWrite(red1[whichbyte], wholebyte - (8 * whichbyte), bitRead(red, 1));
bitWrite(red2[whichbyte], wholebyte - (8 * whichbyte), bitRead(red, 2));
bitWrite(red3[whichbyte], wholebyte - (8 * whichbyte), bitRead(red, 3));
//*** GREEN ***
bitWrite(green0[whichbyte], wholebyte - (8 * whichbyte), bitRead(green, 0));
bitWrite(green1[whichbyte], wholebyte - (8 * whichbyte), bitRead(green, 1));
bitWrite(green2[whichbyte], wholebyte - (8 * whichbyte), bitRead(green, 2));
bitWrite(green3[whichbyte], wholebyte - (8 * whichbyte), bitRead(green, 3));
//*** BLUE ***
bitWrite(blue0[whichbyte], wholebyte - (8 * whichbyte), bitRead(blue, 0));
bitWrite(blue1[whichbyte], wholebyte - (8 * whichbyte), bitRead(blue, 1));
bitWrite(blue2[whichbyte], wholebyte - (8 * whichbyte), bitRead(blue, 2));
bitWrite(blue3[whichbyte], wholebyte - (8 * whichbyte), bitRead(blue, 3));
}//****LED routine end