hey all
so im trying to run a code once
i know if you put it in the setup it should work and it does not when i compile
i get the error
exit status 1
expected unqualified-id before 'if'
i am running a led on and off every second using millis and
my question is how can i interlink the
flex sensor using millis to turn the led off and back on to its original on and off routine
any help is apreciated
here is my code
thank you
//Motor B
int enableB = 3;
int MotorB1 = 2;
int MotorB2 = 4;
//Motor A
int enableA = 5;
int MotorA1 = 6;
int MotorA2 = 7;
//sensor
int flexValue2;
int flexValue;
const int flexPin2 = A1;
const int flexPin = A0;
//timer
unsigned long DELAY_TIME = 10000; // 10 sec
unsigned long delayStart = 0; // the time the delay started
bool delayRunning = false; // true if still waiting for delay to finish
bool motorA1 = false; // keep track of the motor state
//greenpin
const int greenPin = 11;
int ledState = LOW;
unsigned long previousMillis = 0;
const long interval = 1000;
void setup()
{
Serial.begin (9600);
pinMode (enableA, OUTPUT);
pinMode (MotorA1, OUTPUT);
pinMode (MotorA2, OUTPUT);
pinMode (enableB, OUTPUT);
pinMode (MotorB1, OUTPUT);
pinMode (MotorB2, OUTPUT);
pinMode (greenPin, OUTPUT);
motorA1 = false;
digitalWrite(motorA1, LOW);
// start delay
delayStart = millis();
delayRunning = true;
}
//TOP
if (flexValue < 400)
{
Serial.println ("Motion FORWARD");
digitalWrite (MotorB1, LOW);
digitalWrite (MotorB2, HIGH);
}
void loop()
{
{
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
if (ledState == LOW) {
ledState = HIGH;
} else {
ledState = LOW;
}
// set the LED with the ledState of the variable:
digitalWrite(greenPin, ledState);
}
delayStart += DELAY_TIME; // this prevents drift in the delays
// toggle the led
motorA1 = !motorA1;
//MOTOR A FRONT SENSOR
//enabling motor A
Serial.println ("front motor");
digitalWrite (enableA, HIGH);
//do something
flexValue2 = analogRead(flexPin2);
delay (0);
Serial.println(flexValue2);
Serial.print("sensorA: ");
Serial.println(flexValue2);
//motor A Back Sensor
Serial.println ("back motor");
digitalWrite (enableA, HIGH);
//do something
flexValue = analogRead(flexPin);
delay (0);
Serial.println(flexValue);
Serial.print("sensorB: ");
Serial.println(flexValue);
//TOP Motor
//enabling motor A Back Sensor
Serial.println ("top motor");
digitalWrite (enableB, HIGH);
//do something
flexValue = analogRead(flexPin);
delay (0);
Serial.println(flexValue);
Serial.print("sensorB: ");
Serial.println(flexValue);
//BACKWARD
if (flexValue < 400)
{
Serial.println ("Motion Backwards");
digitalWrite (MotorA1, HIGH);
digitalWrite (MotorA2, LOW);
}
if (flexValue > 600)
{
Serial.println ("Stoping motors");
digitalWrite (MotorA1, LOW);
digitalWrite (MotorA2, LOW);
}
//FORWARD
if (flexValue2 > 840)
{
(motorA1 ) ;{
digitalWrite (MotorA1, LOW);
digitalWrite (MotorA2, HIGH); // turn led on
}
}
}
if (flexValue > 550)
{
Serial.println ("Stoping motors");
digitalWrite (MotorB1, LOW);
digitalWrite (MotorB2, LOW);
}
}