Help fixing code

Hi, I really need help on this. I have written this up so far, and have got it looking roughly how I want it. As part of the process though, I have had to label some functions under a made up name, as I don’t know what to call them. I am new to this so bare with me as I know this is a huge project to take on.

essentially I have an arduino nano hooked up to 2 TLC5940 units that are daisy chained and 3 tactile push buttons. There are 8 COMMON ANODE RGB LED’s coming off the Tlc units as well as 3 L293B h-bridge units (one controlling a 12cm fan, 1 controlling a 4cm fan, and one controlling a Peltier unit)

The idea is that when power is turned on, the following will happen:

  • RGB LED 1 turns on with a certain colour to indicate power is on
  • The Large (12cm) fan turns on (at low power setting)
  • RGB LED 2 turns on to indicate fans power level (Low, Medium High, no off).

There are three tactile push button switches, each have there own function:

  • Button 1 controls the power level of the large fan and scrolls through LED’s 2, 3 &4 to show the power level.
  • Button 2 controls LED 5, switching it from Blue to Red and back.
  • Button 3 controls the power level of the Peltier and the Small (4cm) fan as well as turns the, on and off and scrolls through RGB LEDs 6, 7 & 8 to indicate the power level of the Peltier (Low, Medium, High, Off). When it LED 5 is blue, the Peltier is polled in one direction, when LED 5 is red, it is polled in the other direction. The Small fan is only powered on to cool the Peltier and can remain on high when ever the Peltier is turned on, otherwise it stays off.

I do plan to later add more fans and peltiers, but for now, I just want his working.

I will post my code as an attachment, as well as the error message

AirCube_V4.ino (6.73 KB)

The Error message:

Arduino: 1.8.5 (Windows 10), Board: “Arduino Nano, ATmega328P”

C:\Users\Lettie\Desktop\Air3\Coding\AirCube_V4\AirCube_V4.ino: In function ‘void setup()’:

AirCube_V4:71: error: expected primary-expression before ‘)’ token

), 2(

^

AirCube_V4:71: error: expression cannot be used as a function

AirCube_V4:79: error: expected primary-expression before ‘)’ token

), 3(

^

AirCube_V4:79: error: expression cannot be used as a function

AirCube_V4:87: error: expected primary-expression before ‘)’ token

));

^

AirCube_V4:87: error: expression cannot be used as a function

AirCube_V4:93: error: expected primary-expression before ‘)’ token

), 2(

^

AirCube_V4:93: error: expression cannot be used as a function

AirCube_V4:98: error: expected primary-expression before ‘)’ token

));

^

AirCube_V4:98: error: expression cannot be used as a function

AirCube_V4:101: error: expected primary-expression before ‘if’

if (button3PressCount % TLC_Function3 == 0) & (button2PressCount % TLC_Function2 == 0) {

^

AirCube_V4:120: error: expression cannot be used as a function

), 2(

^

AirCube_V4:121: error: expected primary-expression before ‘if’

if (button3PressCount % TLC_Function3 == 1) & (button2PressCount % TLC_Function2 == 0) {

^

AirCube_V4:144: error: expression cannot be used as a function

), 3(

^

AirCube_V4:145: error: expected primary-expression before ‘if’

if (button3PressCount % TLC_Function3 == 2) & (button2PressCount % TLC_Function2 == 0) {

^

AirCube_V4:168: error: expression cannot be used as a function

), 4(

^

AirCube_V4:169: error: expected primary-expression before ‘if’

if (button3PressCount % TLC_Function3 == 3) & (button2PressCount % TLC_Function2 == 0) {

^

AirCube_V4:188: error: expression cannot be used as a function

));

^

AirCube_V4:207: error: ‘numberOfTLC_Function2’ was not declared in this scope

for (int i = 0;i <numberOfTLC_Function2; i++){

^

AirCube_V4:214: error: ‘numberOfTLC_Function3’ was not declared in this scope

for (int i = 0;i <numberOfTLC_Function3; i++) {

^

C:\Users\Lettie\Desktop\Air3\Coding\AirCube_V4\AirCube_V4.ino: In function ‘void loop()’:

AirCube_V4:227: error: ‘numberOfTLC_Funclion1’ was not declared in this scope

if (button1PressCount % numberOfTLC_Funclion1 ==i)

^

AirCube_V4:229: error: ‘TlcAPins’ was not declared in this scope

digitalWrite(TlcAPins*, HIGH);*

  • ^*
    AirCube_V4:231: error: ‘TlcAPins’ was not declared in this scope
    _ digitalWrite(TlcAPins*, LOW);_
    _
    ^_
    AirCube_V4:236: error: ‘numberOfTLC_Function2’ was not declared in this scope
    for (int i = 0; i<numberOfTLC_Function2; i++){
    _
    ^_
    AirCube_V4:238: error: expected primary-expression before ‘}’ token
    _
    }_
    _
    ^_
    AirCube_V4:239: error: ‘TlcBPins’ was not declared in this scope
    _ digitalWrite(TlcBPins, HIGH);
    ^
    AirCube_V4:239: error: ‘i’ was not declared in this scope
    digitalWrite(TlcBPins, HIGH);
    ^
    AirCube_V4:241: error: ‘TlcBPins’ was not declared in this scope
    digitalWrite(TlcBPins, LOW);
    ^
    AirCube_V4:241: error: ‘i’ was not declared in this scope
    digitalWrite(TlcBPins, LOW);
    ^_

    AirCube_V4:246: error: ‘numberOfTLC_Function3’ was not declared in this scope
    for (int i = 0; i<numberOfTLC_Function3; i++){
    _ ^_
    AirCube_V4:247: error: ‘buttom3PressCount’ was not declared in this scope
    if (buttom3PressCount % numberOfTLC_Function3 ==i)
    _ ^
    AirCube_V4:248: error: expected primary-expression before ‘}’ token
    }
    ^
    AirCube_V4:249: error: ‘TlcCPins’ was not declared in this scope
    digitalWrite(TlcCPins, HIGH);
    ^
    AirCube_V4:249: error: ‘i’ was not declared in this scope
    digitalWrite(TlcCPins, HIGH);
    ^
    AirCube_V4:251: error: ‘TlcCPins’ was not declared in this scope
    digitalWrite(TlcCPins, LOW);
    ^
    AirCube_V4:251: error: ‘i’ was not declared in this scope
    digitalWrite(TlcCPins, LOW);
    ^
    exit status 1
    expected primary-expression before ‘)’ token
    This report would have more information with
    “Show verbose output during compilation”*

    option enabled in File → Preferences._

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

The error message is telling you that you have some formatting errors.
Possibly tomany ; or not enough, as well as possibly tomany { }, or not enough.
Check your if statement layering and structure.

if (button3PressCount % TLC_Function3 == 0) & (button2PressCount % TLC_Function2 == 0)

I think you need some extra ( and ), && instead of &.

https://www.arduino.cc/reference/en/language/structure/boolean-operators/logicaland/

Press Ctrl-T in the IDE to get even indenting of the { }, although you have done well with the indenting.
Can you provice links to where you got your Libraries please?

Tom… :slight_smile:
OPs code;

// Air Cube Basic Version 1 by Caitlin Winter
// The Air Cube has several functions that will be controlled by a set of basic push buttons
// Each Push Button will have its own function
// Button 1 will control Air flow,low/medium/high as well as interact with corresponding LEDs to indicate fan speed
// Button 2 will control TECs, by switching polarities of the TECs and interact with the corresponding LED to indicate Hot(Red)/Cold(Blue function
// Button 3 will control the power level of the TECs low/medium/high, as well as turn on/off cooling fans, and indicate power level using LEDs
// This code will first be tested using an Arduino nano then converted and transfered to an ATmega328p
// Buttons are assigned as follows
// Button 1 to Arduino D5 or ATmega 11 (LEDs 2,3,4)
// Button 2 to Arduino D6 or Atmega 12 (LED 5)
// Button 3 to Arduino D7 or ATmega 13 (LEDs 6,7,8) 
// LEDs are assigned as follows
// LED 1 is Power I/O to TCL5940 Output 0(BLUE) and 1(GREEN)
// LED 2 is Fan Low to TLC5940 Output 2(BLUE) and 3(GREEN)
// LED 3 is Fan Medium to TLC5940 Output 4(BLUE) and 5(GREEN)
// LED 4 is Fan High to TLC5940 Output 6(BLUE) and 7(GREEN)
// LED 5 is Hot/Cold indicator to TLC5940 Output 16(BLUE) and 17(RED)
// LED 6 is TEC Low to TLC5940 Output 8(BLUE) and 9(GREEN)
// LED 7 is TEC Medium to TLC5940 Output 10(BLUE) and 11(GREEN)
// LED 8 is TEC High to TLC5940 Output 12(BLUE) and 13(GREEN)
// Big Fan is to TLC5940 Output 22
// TECs are to TLC5940 Output 19 and 19
// Small Fans are to TLC5940 Output 20 and 21
// LED Branding colour values = BLUE 2354 and GREEN 1740 for TLC5940
// Fan (Pin 22) power level values LOW = 1365, MEDIUM = 2730, HIGH = 4095 for TLC5940
// TEC power level values LOW = 286, MEDIUM = 614, HIGH = 819 for TLC5940

#include "Tlc5940.h"
#include "tlc_config.h"
#include "pin_functions.h"

#define D5 = button1Pin;
#define D6 = button2Pin;
#define d6 = button3Pin;

int dataPin = 15;
int latchPin = 13;
int clockPin = 17;
byte leds = 0;
int count1 = 0;
int count2 = 0;
int count3 = 0;

const int button1Pin = 5;
const int button2Pin = 6;
const int button3Pin = 7;

int button1State = 0;
int button2State = 0;
int button3State = 0;
int button1PressCount = 0;
int button2PressCount = 0;
int button3PressCount = 0;

int numberOfTLC_Function1 = 3; //Might need to rename these
int numberOfTlcFunction2 = 2;
int numberOfTlcFunction3 = 4;

void setup() {

// Initialize the tlc5940
Tlc.init();
int TLC_Function1 [] = (1(
      Tlc.set (22, 2730),
    Tlc.set (2, 0),
    Tlc.set (3, 0),
    Tlc.set (4, 2354),
    Tlc.set (5, 1740),
    Tlc.update(),
    delay(500),
), 2(
      Tlc.set (22, 4095),
    Tlc.set (4, 0),
    Tlc.set (5, 0),
    Tlc.set (6, 2354),
    Tlc.set (7, 1740),
    Tlc.update(),
    delay(500),
), 3(
      Tlc.set (22, 1365),
    Tlc.set (6, 0),
    Tlc.set (7, 0),
    Tlc.set (2, 2354),
    Tlc.set (3, 1740),
    Tlc.update(),
    delay(500),
));
int TLC_Function2 [] = (1(
      Tlc.set (16, 0),
    Tlc.set (17, 4095),
    Tlc.update(),
    delay(500),
), 2(
      Tlc.set (16, 4095),
    Tlc.set (17, 0),
    Tlc.update(),
    delay(500),
));

int TLC_Function3 [] = (1(
    if (button3PressCount % TLC_Function3 == 0) & (button2PressCount % TLC_Function2 == 0) {
    Tlc.set (18, 286),
    Tlc.set (19, 0),
    Tlc.set (8, 2354),
    Tlc.set (9, 1740),
    Tlc.set (20, 4095),
    Tlc.update(),
    delay(500),
    } else {
  if (button3PressCount % TLC_Function3 == 0) & (button2PressCount % TLC_Function2 == 1) {
    Tlc.set (18, 0),
    Tlc.set (19, 286),
    Tlc.set (8, 2354),
    Tlc.set (9, 1740),
    Tlc.set (20, 4095,
    Tlc.update(),
    delay(500),
  }
    }
), 2(
    if (button3PressCount % TLC_Function3 == 1) & (button2PressCount % TLC_Function2 == 0) {
    Tlc.set (18, 614),
    Tlc.set (19, 0),
    Tlc.set (8, 0),
    Tlc.set (9, 0),
    Tlc.set (10, 2354),
    Tlc.set (11, 1740),
    Tlc.set (20, 4095),
    Tlc.update(),
    delay(500),
    } else {
  if (button3PressCount % TLC_Function3 == 1) & (button2PressCount % TLC_Function2 == 1) {
    Tlc.set (18, 0),
    Tlc.set (19,614),
    Tlc.set (8, 0),
    Tlc.set (9, 0),
    Tlc.set (10, 2354),
    Tlc.set (11, 1740),
    Tlc.set (20, 4095),
    Tlc.update(),
    delay(500),
  }
    }
), 3(
    if (button3PressCount % TLC_Function3 == 2) & (button2PressCount % TLC_Function2 == 0) {
    Tlc.set (18, 819),
    Tlc.set (19,0),
    Tlc.set (10, 0),
    Tlc.set (11, 0),
    Tlc.set (12, 2354),
    Tlc.set (13, 1740),
    Tlc.set (20, 4095),
    Tlc.update(),
    delay(500),
    } else {
  if (button3PressCount % TLC_Function3 == 2) & (button2PressCount % TLC_Function2 == 1) {
    Tlc.set (18, 0),
    Tlc.set (19,819),
    Tlc.set (10, 0),
    Tlc.set (11, 0),
    Tlc.set (12, 2354),
    Tlc.set (13, 1740),
    Tlc.set (20, 4095),
    Tlc.update(),
    delay(500),
  }
    }
), 4(
    if (button3PressCount % TLC_Function3 == 3) & (button2PressCount % TLC_Function2 == 0) {
    Tlc.set (18, 0),
    Tlc.set (19,0),
    Tlc.set (12, 0),
    Tlc.set (13, 0),
    Tlc.set (20, 0),
    Tlc.update(),
    delay(500),
} else {
  if (button3PressCount % TLC_Function3 == 3) & (button2PressCount % TLC_Function2 == 1) {
    Tlc.set (18, 0),
    Tlc.set (19,0),
    Tlc.set (12, 0),
    Tlc.set (13, 0),
    Tlc.set (20, 0),
    Tlc.update(),
    delay(500),
  }
}
));

// Start fans on low power level with LED on
    Tlc.set (22, 1365);
    Tlc.set (0, 2354);
    Tlc.set (1, 1740);
    Tlc.set (2, 2354);
    Tlc.set (3, 1740);
    Tlc.set (16, 4095);
    Tlc.update();
    delay(500);

for (int i = 0;i <numberOfTLC_Function1; i++){ 
pinMode(dataPin, OUTPUT);
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}
pinMode(button1Pin, INPUT);

for (int i = 0;i <numberOfTLC_Function2; i++){
pinMode(dataPin, OUTPUT);
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}
pinMode(button2Pin, INPUT);

for (int i = 0;i <numberOfTLC_Function3; i++) {
pinMode(dataPin, OUTPUT);
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}
pinMode(button3Pin, INPUT);
}

void loop() 
{
  button1State = digitalRead(button1Pin);
  if (button1State == HIGH){
    for (int i = 0; i<numberOfTLC_Function1; i++){
      if (button1PressCount % numberOfTLC_Funclion1 ==i)
      {
      digitalWrite(TlcAPins[i], HIGH);
    } else {
      digitalWrite(TlcAPins[i], LOW);
    }
  }
    button2State = digitalRead(button2Pin);
  if (button2State == HIGH){
    for (int i = 0; i<numberOfTLC_Function2; i++){
      if (button2PressCount % numberOfTLC_Function2 ==i)
    }
      digitalWrite(TlcBPins[i], HIGH);
    } else {
      digitalWrite(TlcBPins[i], LOW);
    }
  }
    button3State = digitalRead(button3Pin);
  if (button3State == HIGH){
    for (int i = 0; i<numberOfTLC_Function3; i++){
      if (buttom3PressCount % numberOfTLC_Function3 ==i)
    }
      digitalWrite(TlcCPins[i], HIGH);
    } else {
      digitalWrite(TlcCPins[i], LOW);
    }
  }

Hi,
With such a lot going on in your code did you write it in parts, getting each part working before going onto the next?

Then combining the parts in stages, one part at a time and getting the combination working before adding the next?

Looking at your error message, it looks like you have tried to write all your code at once, not a good idea,

What is this bit of code supposed to do?

 int TLC_Function1 [] = (1(
                            Tlc.set (22, 2730),
                            Tlc.set (2, 0),
                            Tlc.set (3, 0),
                            Tlc.set (4, 2354),
                            Tlc.set (5, 1740),
                            Tlc.update(),
                            delay(500),
                          ), 2(
                            Tlc.set (22, 4095),
                            Tlc.set (4, 0),
                            Tlc.set (5, 0),
                            Tlc.set (6, 2354),
                            Tlc.set (7, 1740),
                            Tlc.update(),
                            delay(500),
                          ), 3(
                            Tlc.set (22, 1365),
                            Tlc.set (6, 0),
                            Tlc.set (7, 0),
                            Tlc.set (2, 2354),
                            Tlc.set (3, 1740),
                            Tlc.update(),
                            delay(500),
                          ));

Can you please tell us your electronics, programming, Arduino, hardware experience?

Tom.... :slight_smile:

Thanks for the replies, Unfortunately, as I am still waiting for parts, I haven't been able to build the project to test any of the code yet. So yeah I have been writing it out all in one go, based on other bits of code I have seen that do similar things to what I want. I'll post the libraries in a few mins, I gotta boot up my computer.

I got my libraries from here:

I don't have a great deal of experience with electronics, I basically taught myself everything I knew. Most of what I know is based around building foot pedals for guitars so this is completely different. I only used an Arduino for one other project to create a midi strip controller for a Digitech whammy

What is this bit of code supposed to do?

Can you answer the question please.
The code is a noncense but if we were to know what you thought it was doing then maybe we could put you right.

A button just has two pieces of metal inside which touch together when you push the button.

If you have two pieces of wire that you can jam into the Arduino header then you can make a button. Use the onboard LED. Now you can test the buttons and LEDs part of your code.

That piece of code is supposed to define what I want button 1 to do for controlling the 12cm fan speed and scroll through LEDs 2, 3 & 4 to indicate the fan power level of the fan

SeeTheWinter:
That piece of code is supposed to define what I want button 1 to do for controlling the 12cm fan speed and scroll through LEDs 2, 3 & 4 to indicate the fan power level of the fan

OK well that is nothing like what it attempts to do in the C language.
What that tries to do is to define an integer array with a list of numbers and function calls.

However first off that is not possible in the C language. When you specify a function then it is possible to get the address of the function but that needs putting in a pointer array, but then calling that function is only something you can do with code.

To do what you want you have to use a control function called a switch function. Look up how that works in the Arduino referance document. You get this from the help menu in the Arduino IDE.

#define D5 = button1Pin;
#define D6 = button2Pin;
#define d6 = button3Pin;

Don't ever do this.

Two things - it won't do what you think, and WILL cause all kinds of error messages, and second, don't try to distinguish different entities (D6 vs. d6) by case alone.

const byte D5 = button1Pin; etc.

TolpuddleSartre:
const byte D5 = button1Pin; etc.

?

const byte button1Pin = 5;

Leo…

Wawa:
?

const byte button1Pin = 5;

Leo..

. Who knows what it is supposed to look like?

, don't try to distinguish different entities (D6 vs. d6) by case alone.

Thank you, I didn't spot that.

I appreciate the feedback, but could I please get some direction on things I CAN do to fix the code and not just things I can't do.

I have put a lot of effort in making this code, and although it is wrong, without knowing what needs to be written, only knowing what not to do doesn't help very much when no solution is provided

what not to do doesn't help very much when no solution is provided

What I said was

To do what you want you have to use a control function called a switch function. Look up how that works in the Arduino referance document. You get this from the help menu in the Arduino IDE.

I consider that help. What you now do is to look at the switch construct and see if you can make it do what you want. Have a go at writing the code and if you get lost ask about the bit you got lost with and post your progress so far.

Grumpy Mike, I'm sorry, I wasn't directing that at you, I do thank you for being helpful. I'll try what you said and post an update of my progress. Hopefully it works

Hopefully it works

Well it all has to be right to work.

The others were pointing out other things wrong with the code. However as you did not state what those bits of code were supposed to do then it is hard to tell you how to correct them. I would advise you take the same approach to those. That is look up how that code is supposed to be written in the referance manual and if you don’t understand what you have done wrong ask specific questions.

Even when code compiles that is only half the battle. Then it is a matter of if the instructions you have given the computer will do what you intended it to do. It really helps to have the hardware to test things out, or if you have not you can use an Arduino simulator / emulator.

Build things up from simple code and test every few lines that it is doing what you want. Even when you get good at programming it is the getting the code to do what you want bit that is the hardest. Don’t expect easy answers, but you will get better the more you do.