Sorry for the late reply. I didn't see this until today. Here is some code that produces the compiler error:
Error:
lightbar.cpp: In member function 'void lightbar::set_led(int, int, int, int)':
lightbar.cpp:81: error: expected primary-expression before '}' token
lightbar.cpp:81: error: expected `;' before '}' token
This code is just a little project I am working on and completely unfinished, but if this is a rare case I wanted to be able to demonstrate it:
Relevant code:
Main sketch:
#include "Tlc5940.h"
#include "lightbar.h"
lightbar lightbar;
int counter = 0;
int d = 30;
int r, g, b;
void setup() {
lightbar.init();
r = 0;
g = 0;
b = 0;
}
void loop() {
for(int i=0; i <=1000; i++){
lightbar.set_led(0, i, 0, 0);
lightbar.set_led(1, i, 0, 0);
lightbar.set_led(2, i, 0, 0);
lightbar.set_led(3, i, 0, 0);
lightbar.set_led(4, i, 0, 0);
delay(d);
}
for(int i=1000; i <=1000; i++){
lightbar.set_led(0, 500, 0, i);
lightbar.set_led(1, 500, 0, i);
lightbar.set_led(2, 500, 0, i);
lightbar.set_led(3, 500, 0, i);
lightbar.set_led(4, 500, 0, i);
delay(d);
}
for(int i=1000; i > 0; i--){
lightbar.set_led(0, i, 0, i);
lightbar.set_led(1, i, 0, i);
lightbar.set_led(2, i, 0, i);
lightbar.set_led(3, i, 0, i);
lightbar.set_led(4, i, 0, i);
delay(d);
}
for(int i=0; i <=1000; i++){
lightbar.set_led(0, 0, i, 0);
lightbar.set_led(1, 0, i, 0);
lightbar.set_led(2, 0, i, 0);
lightbar.set_led(3, 0, i, 0);
lightbar.set_led(4, 0, i, 0);
delay(d);
}
}
lightbar.cpp:
#include "Arduino.h"
#include "Tlc5940.h"
#include "lightbar.h"
lightbar::lightbar(){
//Constructor, empty for now
}
// calls Tlc5940.h init function and clears any values on the chip
void lightbar::init(){
//initialize tlc(s)
Tlc.init();
//reset pins to off
Tlc.set(0, 0);
Tlc.set(1, 0);
Tlc.set(2, 0);
Tlc.set(3, 0);
Tlc.set(4, 0);
Tlc.set(5, 0);
Tlc.set(6, 0);
Tlc.set(7, 0);
Tlc.set(8, 0);
Tlc.set(9, 0);
Tlc.set(10, 0);
Tlc.set(11, 0);
Tlc.set(12, 0);
Tlc.set(13, 0);
Tlc.set(14, 0);
Tlc.set(15, 0);
//send data
Tlc.update();
}
void lightbar::set_led(int led, int r, int g, int b){
switch (led) {
case 0:
Tlc.set(0, r);
Tlc.set(1, b);
Tlc.set(2, g);
Tlc.update();
break;
case 1:
Tlc.set(3, r);
Tlc.set(4, b);
Tlc.set(5, g);
Tlc.update();
break;
case 2:
Tlc.set(6, r);
Tlc.set(7, b);
Tlc.set(8, g);
Tlc.update();
break;
case 3:
Tlc.set(9, r);
Tlc.set(10, b);
Tlc.set(11, g);
Tlc.update();
break;
case 4:
Tlc.set(12, r);
Tlc.set(13, b);
Tlc.set(14, g);
Tlc.update();
break;
default:
//Tlc.update();
}
}
void lightbar::set_all(int color){
//reset pins to off
Tlc.set(0, color);
Tlc.set(1, color);
Tlc.set(2, color);
Tlc.set(3, color);
Tlc.set(4, color);
Tlc.set(5, color);
Tlc.set(6, color);
Tlc.set(7, color);
Tlc.set(8, color);
Tlc.set(9, color);
Tlc.set(10, color);
Tlc.set(11, color);
Tlc.set(12, color);
Tlc.set(13, color);
Tlc.set(14, color);
Tlc.set(15, color);
//send data
Tlc.update();
}
void lightbar::clear_all(){
//reset pins to off
Tlc.set(0, 0);
Tlc.set(1, 0);
Tlc.set(2, 0);
Tlc.set(3, 0);
Tlc.set(4, 0);
Tlc.set(5, 0);
Tlc.set(6, 0);
Tlc.set(7, 0);
Tlc.set(8, 0);
Tlc.set(9, 0);
Tlc.set(10, 0);
Tlc.set(11, 0);
Tlc.set(12, 0);
Tlc.set(13, 0);
Tlc.set(14, 0);
Tlc.set(15, 0);
//send data
Tlc.update();
}
lightbar.h:
#ifndef lightbar_h
#define lightbar_h
#define MAX_BRIGHTNESS 1023
#include "Arduino.h"
class lightbar
{
public:
lightbar();
void init();
void set_led(int led, int r, int g, int b);
void set_all(int color);
void clear_all();
private:
//!
};
#endif
Judging by your response, I'm guessing it may not occur in a normal sketch, but my problem may be associated with the switch statement being in a .cpp file?
-Mat