Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

C++ I'm a complete newbie and I'm not sure what went wrong.

C++:
int led = 13;
int pushButton = 2;



void setup () {
 
  Serial.begin(9600);
  pinMode{pushButton, INPUT);
    pinMode(led, OUTPUT);
      
}
 
 
void loop () {
 
  int buttonState = digitalRead(pushButton);
  Serial.printIn(buttonState);
  if (buttonState != 1) {
      digitalWrite(led, HIGH);
  } else {
    digitalWrite (led, LOW);
  }
  delay(1);




}


Hi, so these lines of codes are meant for Tinkercad Arduino. As you can see, these lines of codes were meant to start a circuit but I don't understand what went wrong. It indicated me the errors of this script but due to the fact that I am a complete newbie to coding, I just can't seem to understand. Can anyone be of help? Thanks.

Error details:
In function 'void setup()':
11:10: error: expected ';' before '{' token
17:13: error: a function-definition is not allowed here before '{' token
31:1: error: expected '}' at end of input exit status 1
 
Last edited by a moderator:
Hi there,

So it looks like the issue is on line 5, I haven't tested it yet but on line 5 I believe you have a mismatch of brackets, pinMode{pushButton, INPUT); should be pinMode(pushButton, INPUT);.

[CODE lang="cpp" highlight="5"]int led = 13;
int pushButton = 2;
void setup () {
Serial.begin(9600);
pinMode{pushButton, INPUT);
pinMode(led, OUTPUT);
}
void loop () {
int buttonState = digitalRead(pushButton);
Serial.printIn(buttonState);
if (buttonState != 1) {
digitalWrite(led, HIGH);
} else {
digitalWrite (led, LOW);
}
delay(1);
}[/CODE]
 
And also change printIn to println, else you will get HardwreSerial error. Try this -

C++:
int led = 13;
int pushButton = 2;

void setup () {
  Serial.begin(9600);
  pinMode(pushButton, INPUT);
  pinMode(led, OUTPUT);
}

void loop () {
  int buttonState = digitalRead(pushButton);
  Serial.println(buttonState);
  if (buttonState != 1) {
    digitalWrite(led, HIGH);
  } else {
    digitalWrite(led, LOW);
  }
  delay(1);
}
 
Back
Top Bottom