7879Views3Replies

Author Options:

HELP - Arduino - "Expected constructor, destructor, or type conversion before '(' token" Answered

I have only just received this Arduino UNO and am trying to teach myself the language. I thought it wouldn't be that bad as I am already familiar with python, however, I was getting loads of errors (most of which I have managed to solve from searching through forums) and have landed on this one.

I get this error -

"exit status 1 - expected constructor, destructor, or type conversion before '(' token"

This is my code...

int ledPin = 0; //declares all different pins for different segments of display
int ledPin1 = 1; int ledPin2 = 2; int ledPin3 = 3; int ledPin4 = 4; int ledPin5 = 5; int ledPin6 = 6; int ledPin7 = 7;

int inPin = 5; //declares analogRead pin

int alphaValue = analogRead(inPin);

map(alphaValue, 1, 1023, 1, 4) //maps 1-1023 to 1-4

void setup() { // put your setup code here, to run once: pinMode(0, OUTPUT); //declares pin types pinMode(1, OUTPUT); pinMode(2, OUTPUT); pinMode(3, OUTPUT); pinMode(4, OUTPUT); pinMode(5, OUTPUT); pinMode(6, OUTPUT); pinMode(7, OUTPUT);

pinMode(5, INPUT);

#define low digitalWrite(ledPin, LOW); //defines 'low' digitalWrite(ledPin1, LOW); digitalWrite(ledPin2, LOW); digitalWrite(ledPin3, LOW); digitalWrite(ledPin4, LOW); digitalWrite(ledPin5, LOW); digitalWrite(ledPin6, LOW); digitalWrite(ledPin7, LOW); }

void loop() { // put your main code here, to run repeatedly: if(alphaValue == 1){ low digitalWrite(ledPin, HIGH); digitalWrite(ledPin1, HIGH); digitalWrite(ledPin7, HIGH); digitalWrite(ledPin2, HIGH); digitalWrite(ledPin5, HIGH); digitalWrite(ledPin6, HIGH); } if (alphaValue == 2){

low digitalWrite(ledPin1, HIGH); digitalWrite(ledPin5, HIGH); digitalWrite(ledPin4, HIGH); digitalWrite(ledPin6, HIGH); digitalWrite(ledPin2, HIGH); } if(alphaValue == 3){

low digitalWrite(ledPin, HIGH); digitalWrite(ledPin1, HIGH); digitalWrite(ledPin5, HIGH); digitalWrite(ledPin4, HIGH); } if(alphaValue == 4){

low digitalWrite(ledPin, HIGH); digitalWrite(ledPin1, HIGH); digitalWrite(ledPin5, HIGH); digitalWrite(ledPin4, HIGH); digitalWrite(ledPin6, HIGH); digitalWrite(ledPin7, HIGH); digitalWrite(ledPin3, HIGH); }

}

Discussions

The forums are retiring in 2021 and are now closed for new topics and comments.
0
ptkrf
ptkrf

2 years ago

In arduino sketches you can't call functions outside of setup() and loop() voids. You must move assigning value to int alphaValue and map it in setup() and not before. In case I wasn't clear, see code below (only what you should change):

int inPin = 5; //declares analogRead pin
int alphaValue;/// = analogRead(inPin);
///map(alphaValue, 1, 1023, 1, 4) //maps 1-1023 to 1-4
void setup() {
int alphaValue = analogRead(inPin);
map(alphaValue, 1, 1023, 1, 4); //maps 1-1023 to 1-4
// put your setup code here, to run once:

pinMode(0, OUTPUT); //declares pin type

(sorry for weird formatting of this reply - instructables editor is acting funny...)

0
LOU_DEW747
LOU_DEW747

Reply 2 years ago

Yes I saw this article. Don't really understand but will try to follow what they have said. Thanks anyway xD