As per Paul's suggestion here's a little bump for the thread, if anyone can help me out that would be grand. Thanks.
const int inPin = 2; // the number of the input pin for the button switch
const int outPin1 = 10; // the number of the output1 pin
const int outPin2 = 11; // the number of the output2 pin
const int hallPin = 8; // Hall sensor pin 3rd leg on the right to Arduino 8
int enA = 6;
int state1; // the current state of the output1 pin
int reading; // the current reading from the input pin
int previous = LOW; // the previous reading from the input pin
long time = 0; // the last time the output pin was toggled
long debounce = 200; // the debounce time, increase if the output flickers
int pressCount = 1;
int hallState = 0;
void setup()
{
pinMode(inPin, INPUT_PULLUP);
pinMode(outPin1, OUTPUT);
pinMode(outPin2, OUTPUT);
pinMode(enA, OUTPUT);
pinMode(hallPin, INPUT);
}
void loop()
{
reading = digitalRead(inPin);
if (reading == HIGH && previous == LOW && millis() - time > debounce)
{
state1 = !state1; // Toggle the state
pressCount++;
time = millis();
switch (pressCount % 2)
{
case 0:
digitalWrite(outPin1, HIGH); // Turn on motor direction 1
digitalWrite(outPin2, LOW); //
analogWrite(enA, 100); // Sets motor speed (value between 0-255)
delay (1000); // Runs motor for 1 second
digitalWrite(outPin1, LOW); // Turn off motor direction 1
digitalWrite(outPin2, LOW);
break;
case 1:
hallState = digitalRead(hallPin);
if (hallState == HIGH) // No Magnet
{
digitalWrite(outPin1, LOW); // Run motor direction 2
digitalWrite(outPin2, HIGH);
analogWrite(enA, 100);
}
if (hallState == LOW) {
digitalWrite(outPin1, LOW);
digitalWrite(outPin2, LOW);
}
break;
}
}
previous = reading;
}