Hi, i have started with Arduino so is want to learn the basics. I have written a code but it stil doesn't work. What has to be happening is that when the Magnetic sensor has been activated the servo moves. Can someone help me? The errros says 'expected initializer before 'if'
#include <Servo.h>
const int ledPin = 13;
const int hallPin = 2;
volatile bool ledState = LOW;
Servo myservo;
Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. If your browser doesn't show the posting toolbar then you can just manually add the code tags: [code]``[color=blue]// your code is here[/color]``[/code]
Using code tags and other important information is explained in the How to use this forum post. Please read it.
Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read. If you're using the Arduino Web Editor you will not have access to this useful tool but it's still unacceptable to post poorly formatted code. I recommend you to use the standard IDE instead.
A very helpful troubleshooting tool is the Arduino IDE's Tools > Auto Format feature. If you do an Auto Format and then compare the resulting indentation to your intended program structure, it will quickly point you to where there is a missing or extra brace.
Another useful feature of the Arduino IDE is that when you place the cursor next to one bracket, it puts a box around the matching bracket. If the cursor is next to the closing bracket and the opening bracket is off the screen then it will show the opening bracket line in a tool tip after a short delay.
What possessed you to put ANY code after the { curly brace? What possessed you to type two { in a row? What possessed you to put the } curly brace jammed up against the end of the 4 line in that snippet?
Why do you then NOT type two close curly braces, after you typed two open curly braces?