I am getting this error and fail to see where I have gone wrong. I have run the code in Virtronics Simulator for Arduino and it works perfectly but when used on the Arduino software platform it fails to compile successfully. Changing one thing slightly can change the position of the error, or by saying "#define LIMSWITCH = 3" the error changes slightly to "before = token". The code is to run run the extension and retraction of a landing gear system. Thanks in Advance.
Eoghan
// Use Relay Shield with 4 relays to Extend the Actuator, Retract the Actuator and Unlock the Gear
// Relay 1 uses pin 4 which will be used to extend
// Relay 2 uses pin 7 which will be used to retract
// Relay 3 uses pin 8 which will be used to Unlock
// Relay 4 uses pin 12 which will not be used
// Firstly define what each pin does
#define EXTEND 4;
#define RETRACT 7;
#define UNLOCK 8;
#define GEARSWITCH 2;
#define LIMSWITCH 3; <<Error Here
// define directions
#define LOWER 1
#define RAISE 2
#define STOP 3
void SYSTEM (int direction);
// Gear Switch and Limit Switch pin position is constant
const int GEARSWITCH=2;
const int LIMSWITCH=3;
// Gear Switch and Limit Switch state is variable
int GEARSWITCHSTATE=0;
int LIMSWITCHSTATE=0;
void setup() {
// Initialize Actuator movements and Locking Solenoid as outputs
// Initialize Gear and Limit Switches as inputs
pinMode(EXTEND, OUTPUT);
pinMode(RETRACT, OUTPUT);
pinMode(UNLOCK, OUTPUT);
pinMode(GEARSWITCH, INPUT);
pinMode(LIMSWITCH, INPUT);
}
void loop() {
// Read the state of the Gear Switch Value
GEARSWITCHSTATE=digitalRead(GEARSWITCH);
// Check to see if switch is on. If it is on then the Gear Switch state is HIGH
if (GEARSWITCHSTATE == HIGH && LIMSWITCHSTATE == LOW) {
// Lower the system by extending the Actuator
SYSTEM(LOWER);
}
// Read the state of the Limit Switch Value
LIMSWITCHSTATE=digitalRead(LIMSWITCH);
// Check the state of the Limit Switch, if it is pressed then it is HIGH
if (LIMSWITCHSTATE == HIGH) {
// Stop the extension motion of the Actuator
SYSTEM(STOP);
}
// Check to see if Gear switch is off. If it is then the Gear Switch state is LOW
if (GEARSWITCHSTATE == LOW && LIMSWITCHSTATE == HIGH ) {
// Raise the landing gear by Unlocking then Retracting
SYSTEM(RAISE);
}
}
void SYSTEM(int direction) {
if (direction == LOWER) {
digitalWrite(EXTEND, HIGH);
digitalWrite(RETRACT, LOW);
digitalWrite(UNLOCK, LOW);
}
if (direction == RAISE) {
// Unlock the Gear and Retract the Actuator.
// Delay Retraction to ensure gear is fully unlocked prior to rotation to avoid damage
digitalWrite(UNLOCK, HIGH);
delay(5000);
digitalWrite(RETRACT, HIGH);
// Allow sufficient time for the Actuator to Retract to the 'At Home' position before cutting power so as to conserve energy
delay(20000);
digitalWrite(EXTEND, LOW);
digitalWrite(RETRACT, LOW);
digitalWrite(UNLOCK, LOW);
}
if(direction == STOP) {
digitalWrite(EXTEND, LOW);
digitalWrite(RETRACT, LOW);
digitalWrite(UNLOCK, LOW);
}
}