Go Down

Topic: Arduino error: expected '(' before numeric constant (Read 744 times) previous topic - next topic

darragh_condell

Hello,

I am trying to write code so that the timing of my LED sequence changes when I change the voltage level on input A.

Can you help me get past the compiler error please?
expected '(' before numeric constant

int red = 13;
int yellow = 12;
int green = 11;
int blue = 10;
int A = 9;
int B = 8;


// the setup routine runs once when you press reset:
void setup() {               
  // initialize the digital pin as an output.
  pinMode(red, OUTPUT);
  pinMode(yellow, OUTPUT);
pinMode(green, OUTPUT);
pinMode(blue, OUTPUT);
pinMode(A, INPUT);
}

// the loop routine runs over and over again forever:
void loop(){
  digitalWrite(red, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(900);               // wait for a second
  digitalWrite(red, LOW);    // turn the LED off by making the voltage LOW
  delay(200);

  digitalWrite(red, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(900);               // wait for a second
  digitalWrite(red, LOW);    // turn the LED off by making the voltage LOW
  delay(100);
 
  {digitalWrite(yellow, HIGH);
delay(900);
digitalWrite(yellow, LOW);
delay(200);}

 {digitalWrite(yellow, HIGH);
delay(900);
digitalWrite(yellow, LOW);
delay(200);}

  {digitalWrite(green, HIGH);
delay(900);
digitalWrite(green, LOW);
delay(200);}

 {digitalWrite(green, HIGH);
delay(900);
digitalWrite(green, LOW);
delay(200);}

 {digitalWrite(blue, HIGH);
delay(900);
digitalWrite(blue, LOW);
delay(200);}

  {digitalWrite(blue, HIGH);
delay(900);
digitalWrite(blue, LOW);
delay(200);}


if INPUT A = HIGH;

  digitalWrite(red, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(200);               // wait for a second
  digitalWrite(red, LOW);    // turn the LED off by making the voltage LOW
  delay(200);

  digitalWrite(red, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(200);               // wait for a second
  digitalWrite(red, LOW);    // turn the LED off by making the voltage LOW
  delay(200);
 
  {digitalWrite(yellow, HIGH);
delay(200);
digitalWrite(yellow, LOW);
delay(200);}

 {digitalWrite(yellow, HIGH);
delay(200);
digitalWrite(yellow, LOW);
delay(200);}

  {digitalWrite(green, HIGH);
delay(200);
digitalWrite(green, LOW);
delay(200);}

 {digitalWrite(green, HIGH);
delay(200);
digitalWrite(green, LOW);
delay(200);}

 {digitalWrite(blue, HIGH);
delay(200);
digitalWrite(blue, LOW);
delay(200);}

  {digitalWrite(blue, HIGH);
delay(200);
digitalWrite(blue, LOW);
delay(200);}}


PaulS

Code: [Select]
if INPUT A = HIGH;
You are NOT programming in whatever language you are used to.

{Why} {is} {your} {code} {full} {of} {useless} {curly} {braces} {?}
The art of getting good answers lies in asking good questions.

Delta_G

You shouldn't use single letters for variable names.  You definitely shouldn't use single capital letters.  Many of those are already defined as macros in the core.  When they get expanded into what you though was a variable name the errors that are produced can be crazy hard to figure out.  Give your variables descriptive names so you know what they represent.

|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

UKHeliBob

Code: [Select]
if INPUT A = HIGH;
Wow.  So many mistakes in 1 line

The test expression should be in brackets
What is being tested ?  Is it INPUT, A or a variable named INPUT A, which has a illegal space in its name
= is for assignment, == is for comparison
If statements almost never end with a semicolon

The problems continue after the test.  Should it return true, how does the compiler know which statement or statements to execute ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

darragh_condell

Code: [Select]
if INPUT A = HIGH;
You are NOT programming in whatever language you are used to.

{Why} {is} {your} {code} {full} {of} {useless} {curly} {braces} {?}
I am new to Arduino, can you please explain to me what my code should be if not "if INPUT A = HIGH"

AWOL

Have you seen any of the many worked examples in the IDE?
"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

Delta_G

I am new to Arduino, can you please explain to me what my code should be if not "if INPUT A = HIGH"
That's a great guess at how a language might be written.  And if I ever write a language I might even try to make it look like that.  But unfortunately we don't get to make this one up.  There is a specific function for reading the state of an input.  You should take a little time to read through the reference materials on this site and look at some of the example codes that come with the IDE.  Another really helpful thing to take in would be a basic introductory tutorial on C++.  There are a multitude of those all over the internet.  Learning at least the basics of the language is a must before diving into any programming project. 
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

darragh_condell

Have you seen any of the many worked examples in the IDE?

No, are these examples on the site or in the software?

AWOL

No, are these examples on the site or in the software?
In the IDE. The thing you used to compile the code.
Under "examples"
"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

Delta_G

Another good place to learn is by going to the top of this page under Learning. 

|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

KeibertH

necesito ayuda con mi codigo por favor, no compila y me da un error: expected ')' before numeric constant
                                                                                        exit status 1
                                                                                        expected ')' before numeric constant

el codigo es para ecender 2 led con control remoto infrarrojo y ajustar la luminosidad de cada led con el control,lo voy a subir a un arduino nano,ATmega168

el ide arduino es 1.8.8  en windows 10                                           este es mi codigo:


#include <IRremote.h>


#define white 0xF171
#define offw 0xF1B1
#define lighta 0xF129
#define lightb 0xF1A9
#define red 0xF1A1
#define offr 0xF121
#define lightA 0xF1C9
#define lightB 0xF149
#define MAX_BRIGHT 255
#define SL_BD_RT 9600


#define RECV_PIN 11
#define LED_PIN 5 //
#define LED_PIN 6  //

byte ledState;
IRrecv irrecv(RECV_PIN);
decode_results results;
boolean power_state = LOW;

void setup(){
  Serial.begin(SL_BD_RT);
  irrecv.enableIRIn();  //
  pinMode(LED_PIN 5 ,OUTPUT);
  pinMode(LED_PIN 6 ,OUTPUT);  //
}

void loop() {
  if (irrecv.decode(&results)) {  //
    //
    switch(results.value) {

      //
      case offw:
        //
           ledState = 125;
           digitalWrite(LED_PIN 5, LOW);  //
      break;

      case offr:
        //
           ledState = 125;
           digitalWrite(LED_PIN 6, LOW);  //
      break;

      case white:
           digitalWrite(LED_PIN 5, HIGH); //
      break;

      case red:
           digitalWrite(LED_PIN 6, HIGH); //
      break;

      //
      case lightb:
             ledState -=10;
             if (ledState > 0){
             analogWrite(LED_PIN 5, ledState);  //
             }
       break;

       //
       case lightB:
             ledState -=10;
             if (ledState > 0){
             analogWrite(LED_PIN 6, ledState);  //   
             }
       break;

       //
       case lighta:
            if (ledState < MAX_BRIGHT){
               ledState +=10;
            }
           analogWrite(LED_PIN 5, ledState);  //
      break;

        //
        case lightA:
             if (ledState < MAX_BRIGHT){
                ledState +=10;
             }
           analogWrite(LED_PIN 6, ledState);     
     break;

       delay(200);  //
       irrecv.resume(); //
     }
   }

AWOL

Code: [Select]
  pinMode(LED_PIN 5 ,OUTPUT);
  pinMode(LED_PIN 6 ,OUTPUT);
Eight there.
"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

Go Up