i have a expected unqualified-id before 'void'
;const int sensor1 = 2
;const int sensor2= 3
,
void setup() {
;const val = 1
#define sensor1 A3
#define sensor2 A4
what do i do plsss help
i have a expected unqualified-id before 'void'
;const int sensor1 = 2
;const int sensor2= 3
,
void setup() {
;const val = 1
#define sensor1 A3
#define sensor2 A4
what do i do plsss help
Why do you put the ; in front of the code when it is supposed to be at the end of the code?
Why are you unable to use code tags when posting code?
An example of using code tags and of using the proper syntax.
const int p1 = 9;
Welcome to the forum
Your post has been moved to a more suitable forum category
Start by posting your full sketch, using code tags when you do. The few line that you posted look very odd. Do they really look like that in the IDE ?
You cannot program in ANY programming language without spending a littlle time learning the basics of its syntax. You cannot simply make it up as you go along.
Why put a define inside the setup() function where the define will go out of scope?
It's an odd thing to do for sure, but I don't think the preprocessor knows anything about scope.
Correct. The preprocessor has no concept of "scope". It simply a text substitution. As long as the macro is referenced after it's defined (later in the file), all is well.
void setup() {
Serial.begin(115200);
delay(1000);
#define STRING "Hello World"
}
void loop() {
Serial.println(STRING);
delay(1000);
}
To the compiler, your code looks sort of like this:
;
const int sensor1 = 2;
const int sensor2 = 3, void setup()
{
;
const val = 1
#define sensor1 A3
#define sensor2 A4
Since there is no ';' between '3,' and 'void' they are considered part of the same statement and putting 'void' there makes no sense to the compiler.
this is my code and on line 15 i get this error:
expected constructor, destructor, or type conversion before '(' token
what should i put on this
int led = 13
;int sensor1 = 2
;int sensor2 = 3
;int val = 0;
void setup(){
pinMode (led, OUTPUT)
;pinMode (sensor1, INPUT)
;pinMode (sensor2, INPUT)
;Serial.begin(9600);
}
void setup();
digitalRead (sensor1) // this is line 15
if (val== HIGH)
{
digitalRead(sensor2)
if (val = LOw)
digitalWrite(led, HIGH);
delay(500);
}
Hi,
There are several errors in your topic.
The main one is that you have posted without using the </> tags.
Read :
and then correct your topic by enclosing the code in tags.
Your code has several errors.
";" are at the beginning of the statement and should be at the end.
Duplicity of the setup() function.
This is not allowed by the Arduino compiler.
But even if it were allowed your second setup() is wrong.
The brace "{" is not where should be.
The loop() function is also missing. "void loop()"
Your two topics on the same or similar subject have been merged.
Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.
Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you won’t have to keep explaining your project repeatedly.
Repeated duplicate posting could result in a temporary or permanent ban from the forum.
Could you take a few moments to Learn How To Use The Forum
It will help you get the best out of the forum in the future.
Thank you.
You can't have a function call (like digitalRead(sensor1)
) outside of a function. What function did you intend that code to be in? Was it supposed to be part of 'setup()' or is it part of the 'loop()' function that you forgot to define?
int led = 13;
int sensor1 = 2;
int sensor2 = 3;
int val = 0;
void setup() {
pinMode(led, OUTPUT);
pinMode(sensor1, INPUT);
pinMode(sensor2, INPUT);
Serial.begin(9600);
}
void setup();
digitalRead(sensor1) // this is line 15
if (val == HIGH) {
digitalRead(sensor2) if (val = LOw)
digitalWrite(led, HIGH);
delay(500);
}
I meant for it to be a loop and I tried reviewing it. I have researched on it and I keep on getting the same error is this better?
<
int led = 13;
int sensor1 = 2;
int sensor2 = 3;
int val = 0;
void setup(){
pinMode (led, OUTPUT)
;pinMode (sensor1, INPUT)
;pinMode (sensor2, INPUT)
;Serial.begin(9600);
}
void loop();
{
digitalRead (sensor1)
if (val== HIGH)
digitalRead(sensor2)
if (val = LOw)
digitalWrite(led, HIGH);
delay(500);} >
I do not have the arduino IDE in front of me right now and I am sorry if this is incorrectly formatted.
You seem to have major problems with semicolons.
Yes, it is better. Now you only have one extra ';', two missing ';', a statement with no effect, testing a variable you don't set, wrong capitalization on 'LOW', and using '=' where you meant '=='.
It looks like what you meant to do was:
void loop() {
if (digitalRead(sensor1) == HIGH
&& digitalRead(sensor2) == LOW)
digitalWrite(led, HIGH);
delay(500);
}
Thank you so much for helping I will try to do this and update if it works!
I have on last question I will connect this code with my arduino uno in this code will I need to add anywhere which place in the arduino uno will the sensor or led be connected for example; A2, A3, etc.
You appear to be using pins 2, 3, and 13.
If you have analog inputs you should use analog input pins:
int led = 13;
int sensor1 = A2;
int sensor2 = A3;
pinMode (led, OUTPUT);
analogRead(sensor1)
analogRead(sensor2)
digitalWrite(led, HIGH);
That makes a bit more sense thank you!
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.