Go Down

Topic: Using Multiple Pushbuttons as Toggles (Read 244 times) previous topic - next topic

BasicJoel

Hello!

It's kind of a long code, thanking you in advance for taking a look at it!

My circuit includes 5 pushbuttons that act as inputs to 5 analog pins, signaling to turn either "ledPin1" or "ledPin2" on/off. As well as two pushbuttons that start two seperate loops for sensors that will be used later on. The led's being used are simply for testing and will be switched out later for connections to relays to allow current to flow pos>neg or neg>pos to a DC motor so it can rotate in both directions.

Is there a way I can change this code so as if Ledpin1 is turned on, LedPin2 is turned off and vice versa? Also if my "stop" is pressed. I don't have to press stop again to turn ledPin1 or LedPin2 back on again?
Any help is greatly appreciated, I'm continuing to work on this and will definitely be checking back here often!

Code: [Select]

/* Author: Joel Guevara
   Date: 10/20/19
   Pushbutton control of a DC Motor
*/
const int  buttonPin1 = A15;    // the pin that the pushbutton is attached to
const int  buttonPin2 = A14;    // the pin that the pushbutton is attached to
const int  buttonPin3 = A13;    // the pin that the pushbutton is attached to
const int  buttonPin4 = A12;    // the pin that the pushbutton is attached to
const int  buttonPin5 = A11;   // the pin that the pushbutton is attached to
const int  ledPin1 = 12;       // the pin that the LED is attached to
const int  ledPin2 = 13;       // the pin that the LED is attached to

//Constants for Utlrasonic
int trigPin = 8;                          //Sensor Trip pin connected to Arduino pin 8
int echoPin = 9;                          //Sensor Echo pin connected to Arduino pin 9

//Variables for Ultrasonic
int   myCounter = 0;                      //declare your variable myCounter and set to 0
float pingTime;                           //time for ping to travel from the sensor to the target and return
float targetDistance;                     //Distance to Target in Centimeters
float speedOfSound = 34300;               //Speed of sound in cm/s

//Constants for Photocells
const int pResistor1 = A0;
const int pResistor2 = A1;
const int pResistor3 = A2;                 // Photoresistor at Arduino analog pins

//Variables for Photocells
int SensorValue1;
int SensorValue2;
int SensorValue3;                          // Store value from photoresistor (0-1023)'

// Variables will change:
int buttonPushCounter1 = 0;   // counter for the number of button presses
int buttonPushCounter2 = 0;   // counter for the number of button presses
int buttonPushCounter3 = 0;   // counter for the number of button presses
int buttonPushCounter4 = 0;   // counter for the number of button presses
int buttonPushCounter5 = 0;   // counter for the number of button presses

int buttonState1 = 0;         // current state of the button1
int buttonState2 = 0;         // current state of the button2
int buttonState3 = 0;         // current state of the button3
int buttonState4 = 0;         // current state of the button4
int buttonState5 = 0;         // current state of the button5

int lastButtonState1 = 0;     // previous state of the button1
int lastButtonState2 = 0;     // previous state of the button2
int lastButtonState3 = 0;     // previous state of the button3
int lastButtonState4 = 0;     // previous state of the button3
int lastButtonState5 = 0;     // previous state of the button3


void setup() {
  // initialize the button pin as a input:
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT_PULLUP);
  pinMode(buttonPin3, INPUT_PULLUP);
  pinMode(buttonPin4, INPUT_PULLUP);
  pinMode(buttonPin5, INPUT_PULLUP);
  pinMode(pResistor1, INPUT);
  pinMode(pResistor2, INPUT);
  pinMode(pResistor3, INPUT);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);

  // initialize the LED as an output:
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);


  // initialize serial communication:
  Serial.begin(9600);
}

void loop() {
  // read the pushbutton input pin:
  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);
  buttonState3 = digitalRead(buttonPin3);
  buttonState4 = digitalRead(buttonPin4);
  buttonState5 = digitalRead(buttonPin5);


  if (buttonState1 != lastButtonState1) {               // Compare the buttonState to its previous state
    if (buttonState1 == HIGH) {                         // if the state has changed, increment the counter
      buttonPushCounter1++;                             // if the current state is HIGH then the button went from off to on:
      Serial.println("MotorForward : ON ");
      Serial.print("number of button pushes1: ");
      Serial.println(buttonPushCounter1);
    }
    else {
      Serial.println("MotorForward : OFF");
    }
  }
  if (buttonState2 != lastButtonState2) {
    if (buttonState2 == LOW) {
      buttonPushCounter2++;
      Serial.println("MotorReverse : ON");
      Serial.print("number of button pushes2: ");
      Serial.println(buttonPushCounter2);
    }
    if (buttonPushCounter2 % 2 == 1) {
      Serial.println("MotorReverse : OFF");

    }
  }
  if (buttonState3 != lastButtonState3) {
    if (buttonState3 == LOW) {
      buttonPushCounter3++;
      Serial.println("Stop : ON");
      Serial.print("number of button pushes3: ");
      Serial.println(buttonPushCounter3);
    }
    if (buttonPushCounter3 % 2 == 1) {
      Serial.println("Stop : OFF");

    }
  }
  if (buttonState4 != lastButtonState4) {
    if (buttonState4 == LOW) {
      buttonPushCounter4++;
      buttonPushCounter5 = 1;
      Serial.println("Photocell : ON");
      Serial.print("number of button pushes4: ");
      Serial.println(buttonPushCounter4);
    }

  }
  if (buttonState5 != lastButtonState5) {
    if (buttonState5 == LOW) {
      buttonPushCounter5++;
      buttonPushCounter4 = 1;
      Serial.println("Ultrasonic : ON");
      Serial.print("number of button pushes5: ");
      Serial.println(buttonPushCounter5);
    }
  }


  lastButtonState1 = buttonState1;                    // save the current state as the last state, for next time through the loop
  lastButtonState2 = buttonState2;
  lastButtonState3 = buttonState3;
  lastButtonState4 = buttonState4;
  lastButtonState5 = buttonState5;

  if (buttonPushCounter1 % 2 == 0) {
    digitalWrite(ledPin1, HIGH);
    digitalWrite(ledPin2, LOW);
  }
  if (buttonPushCounter2 % 2 == 0) {
    digitalWrite(ledPin1, LOW);
    digitalWrite(ledPin2, HIGH);
  }
  if (buttonPushCounter3 % 2 == 0) {
    digitalWrite(ledPin1, LOW);
    digitalWrite(ledPin2, LOW);
  }

  if (buttonPushCounter4 % 2 == 0 && buttonPushCounter5 % 2 != 0) {
    PhotoCellCode();

  }
  if (buttonPushCounter4 % 2 != 0 && buttonPushCounter5 % 2 == 0) {
    UltrasonicCode();
  }

  else {
    digitalWrite(ledPin1, LOW);
    digitalWrite(ledPin2, LOW);
  }

}
void PhotoCellCode() {
  //not included here because of post limit


void UltrasonicCode() {

  //not included here because of post limit


MorganS

Is there a way I can change this code so as if Ledpin1 is turned on, LedPin2 is turned off and vice versa?
Yes, that is what this code does...
Code: [Select]
  if (buttonPushCounter1 % 2 == 0) {
    digitalWrite(ledPin1, HIGH);
    digitalWrite(ledPin2, LOW);
  }
  if (buttonPushCounter2 % 2 == 0) {
    digitalWrite(ledPin1, LOW);
    digitalWrite(ledPin2, HIGH);
  }


What is it doing that you don't expect?

I don't like to use the % operator like this. It's a relatively "expensive" operation for the Arduino to perform. And it's limiting you to only two states on the two buttons. With the way you have it, adding a "stop" button would have to set the two button counters back to some known combination of 0,1,2 that isn't immediately obvious.

It would be much better to re-write this as a "state machine" so that pressing button 1 moves you from the "all off" state to the "1 on" state and pressing "stop" moves you from any state back to the "all off" state. See Grumpy Mike's Tutorial on state machines.
"The problem is in the code you didn't post."

BasicJoel

I included the % statement to perform that switch but it wasn't turning the opposite LED off, it might be wiring thing...

I had tried making manual adjustments to the "mycounter" values to do this but it would cause some weird flashing that would be a problem later on (Its driving a pretty heavy duty motor and for a 1 HP motor to try switch from forward to reverse at 1800 RPM might cause some gear shearing)

A quick question on state machines before I rewrite most of this, do you think it's still possible to include the 4th and 5th pushbuttons to start one of two seperate loops ("void Photocell" and "void Ultrasonic") or should I keep that as is?

MorganS

You haven't shown us what's in those functions. Since you use the word "loop" then I think you've got a for() or while() loop in there. That's bad.

Make loop() loop. That's its job. You can have multiple overlapping state machines. eg. in state "doUltrasonic" you can call the ultrasonic code. That might be a state machine itself. But write that code so that it completes its task in a few milliseconds. Then it can return to loop() and you can check all the buttons and operate the motors.

Alternatively, always call the ultrasonic code, but its state machine first looks to see what state the main state machine is in. This is useful if it needs to influence the state of the main state machine - eg. reverse the robot when a wall is detected. But it may have its own state machine, like it needs to have two 'good' detections before it decides that there really is a wall.
"The problem is in the code you didn't post."

lastchancename

Without looking at all your code, I suggest a struct{} for each button, and an array[] of those structs.  Then your code will be a lot shorter and easier to follow.
Experienced responders have a nose for laziness, (they were beginners once)... Sure, there are trolls, chest-beaters, and pretenders - but the help you'll get here is about as good as it gets - if you try to help youself!.

BasicJoel

#5
Oct 21, 2019, 05:13 am Last Edit: Oct 21, 2019, 05:16 am by BasicJoel
This is the remainder of the code:

Code: [Select]

void PhotoCellCode() {
  SensorValue1 = analogRead(pResistor1);                  //get the value from input pin 1
  SensorValue2 = analogRead(pResistor2);
  SensorValue3 = analogRead(pResistor3);
  delay(100);

  Serial.print("-----------------| ");
  Serial.print(SensorValue1);
  Serial.print(",");
  Serial.print(SensorValue2);
  Serial.print(",");
  Serial.println(SensorValue3);                           //print the value to Serial monitor


  if (SensorValue1 < 300 && SensorValue2 < 300)            //if two are dark turn motor off
  {
    digitalWrite(ledPin1, LOW);
    digitalWrite(ledPin2, LOW);                                                                          // stop reverse
  }
  if (SensorValue1 < 300 && SensorValue3 < 300)
  {
    digitalWrite(ledPin1, LOW);
    digitalWrite(ledPin2, LOW);                                                                           // stop reverse
  }
  if (SensorValue2 < 300 && SensorValue3 < 300)
  {
    digitalWrite(ledPin1, LOW);
    digitalWrite(ledPin2, LOW);                                                                           // stop reverse
  }
  else
  {
    digitalWrite(ledPin1, HIGH);
    //else, keep the motor on
  }
}

void UltrasonicCode() {
  digitalWrite(trigPin, LOW);                             //Set trigger pin low
  delayMicroseconds(20);                                  //Let signal settle
  digitalWrite(trigPin, HIGH);                            //Set trigPin high
  delayMicroseconds(15);                                  //Delay in high state
  digitalWrite(trigPin, LOW);                             //ping has now been sent
  delayMicroseconds(10);                                  //Delay in high state

  pingTime = pulseIn(echoPin, HIGH);                      //pingTime in microceconds
  pingTime = pingTime / 1000000;                          //convert pingTime to seconds by dividing by 1000000 (microseconds in a second)
  targetDistance = speedOfSound * pingTime;               //Set targetdistance value (in cm)
  targetDistance = targetDistance / 2;                    //Remember ping travels to the target and back from the target, so you must divide by 2 for actual target distance.
  delay(250);
  Serial.print("Distance: ");                             //Print Distance
  Serial.println(targetDistance);                         //Pause to let things settle

  if ( targetDistance >= 10 ) {                           // Stop motor if too close
    digitalWrite(ledPin1, LOW);
    digitalWrite(ledPin2, LOW);
  }
  else {
    digitalWrite(ledPin1, HIGH);

  }
}


Its close to what you were guessing where in the ultrasonic loop, if an object is too close both pins should turn off and with the photocell code if two of three photocells do not receive light than both pins are turned off

I am trying to condense the code wherever possible, is there anywhere you would suggest looking at for how to use struct and array?

lastchancename

Whenever you see yourself using thingy1 and thingy2 etc is a good indicator to use arrays.

Your button pins, states and prevStates could all be in a struct for each pin. Then use put the structs in an array..

e.g pseudocode ...
Code: [Select]
struct {
   byte pin;
   bool state;
   bool prevState = !state;
} pinstruct;

pinstruct mypins[numpins];

mypins[0].pin = 7;
mypins[0].state = digitalread(mypins[0].pin);

if ( mypins[0].state != mypins[0].prevState ) {
    do_something;
}


This could be taken further, but I'm on a tablet in bed, so typing is tricky!
Experienced responders have a nose for laziness, (they were beginners once)... Sure, there are trolls, chest-beaters, and pretenders - but the help you'll get here is about as good as it gets - if you try to help youself!.

GoForSmoke

#7
Oct 21, 2019, 08:50 am Last Edit: Oct 21, 2019, 09:01 am by GoForSmoke
Hello!

It's kind of a long code, thanking you in advance for taking a look at it!

My circuit includes 5 pushbuttons that act as inputs to 5 analog pins, signaling to turn either "ledPin1" or "ledPin2" on/off. As well as two pushbuttons that start two seperate loops for sensors that will be used later on. The led's being used are simply for testing and will be switched out later for connections to relays to allow current to flow pos>neg or neg>pos to a DC motor so it can rotate in both directions.

Is there a way I can change this code so as if Ledpin1 is turned on, LedPin2 is turned off and vice versa? Also if my "stop" is pressed. I don't have to press stop again to turn ledPin1 or LedPin2 back on again?
Any help is greatly appreciated, I'm continuing to work on this and will definitely be checking back here often!
You need to learn about arrays!
https://www.arduino.cc/reference/en/language/variables/data-types/array/

Code: [Select]

const byte  buttonPin[ 5 ] = { A15, A14, A13, A12, A11 };  // button pins in array
const byte  ledPin[ 2 ] = { 12, 13 };       // the variable name is the comment

//Constants for Utlrasonic
int trigPin = 8;                          //Sensor Trip pin connected to Arduino pin 8
int echoPin = 9;                          //Sensor Echo pin connected to Arduino pin 9

//Variables for Ultrasonic
int   myCounter = 0;                      //declare your variable myCounter and set to 0

// do this math with integers, use smaller units if you want more precision like mm instead of m
// unsigned long is good for 9 places, usually faster than 6-places float vars
// when I wrote accounting code in the 80's it had to be to the penny, I used integers and it was.
// -- time with micros() when timing counts. millis() skips 6 values out of every 256, randomly 1 ms off.
unsigned long pingMicros;             //time for ping to travel from the sensor to the target and return
unsigned long targetCm;                                //Distance to Target in Centimeters
unsigned long speedOfSound = 34300;               //Speed of sound in cm/s
// speed of sound changes with air temperature. Very cold air slows sound noticeably.
// you may want to calibrate that speedOfSound value against a reflector at known distance.


//                          ALL OF THESE INTS --- if the value can be 0 to 255, use a byte not an int
//Constants for Photocells
const int pResistor1 = A0;     // make this an array, keep on
const int pResistor2 = A1;
const int pResistor3 = A2;                 // Photoresistor at Arduino analog pins

//Variables for Photocells
int SensorValue1;
int SensorValue2;
int SensorValue3;                          // Store value from photoresistor (0-1023)'



Enough for now, please make your variables into arrays after reading about arrays

Your code should get shorter.
1) http://gammon.com.au/blink  <-- tasking Arduino 1-2-3
2) http://gammon.com.au/serial <-- techniques howto
3) http://gammon.com.au/interrupts
Your sketch can sense ongoing process events in time.
Your sketch can make events to control it over time.

MorganS

Not everything is an array. You said you have a "stop" button? Other buttons might be "go forward" or "reverse"? Use those names for buttons in your code.

The photocells are candidates for an array, since the threshold 300 is the same for all and you don't seem to care which one is high. You could write that as an array but the big fat if-else would still look about the same.

You have no loops in the additional code. Good. But you have delays and you have Serial prints. Try to keep all the printing "display code" in one place. The printing you have is good for debugging but should be removed as soon as you know the sensor values are good.
"The problem is in the code you didn't post."

GoForSmoke

Just a thought that if you use micros timing for accuracy, your speed of sound is 343mm/ms.
And the micros() timer changes every 4 microseconds not every 1. The low 2 bits are always 0.

( 343mm/ms x micros us ) / 2000 = mm distance includes 2-way ping.

for 3 micros the length is 0.5mm, the every 4 timer can be off by that much.
Integer math drops the mm fraction.
At cm output you are more sure.

10 degrees C temperature difference will make a small difference, maybe none at cm scale.

Variables in arrays can all share the same code. You don't need a line or more of code for each variable name, they all have the array name and an index number, position in the array. It lets you use a LOT less code, debug less code.
 

1) http://gammon.com.au/blink  <-- tasking Arduino 1-2-3
2) http://gammon.com.au/serial <-- techniques howto
3) http://gammon.com.au/interrupts
Your sketch can sense ongoing process events in time.
Your sketch can make events to control it over time.

BasicJoel

I appreciate all the information on arrays and I was hoping that by reorganizing some of the code that it might make the code run a little better and it did! I'm getting the 5V output i need to trigger my relays but now for some reason when "ForwardPin" or "ReversePin" start outputting the 5V they don't turn off with another button push.

Here's the updated code, I couldn't quite figure out struct formatting but the arrays make it a lot easier to read I think.

Code: [Select]

const byte  buttonPin[] = { A15, A14, A13, A12 };    // button pins in array
const byte  ForwardPin = 12;
const byte  ReversePin = 13;

//Constants for Utlrasonic
int trigPin = 8;                                           //Sensor Trip pin connected to Arduino pin 8
int echoPin = 9;                                           //Sensor Echo pin connected to Arduino pin 9

//Variables for Ultrasonic
int myCounter = 0;                                         //declare your variable myCounter and set to 0

//Constants for Ultrasonic
unsigned long pingTime;                                    //time for ping to travel from the sensor to the target and return
unsigned long targetDistance;                              //Distance to Target in Centimeters
unsigned long speedOfSound = 34300;                        //Speed of sound in cm/s

//Constants for Photocell
const byte pResistor [3] = { A0, A1, A2 };                 // Photoresistor at Arduino analog pins

//Variables for Photocells
int SensorValue1;
int SensorValue2;
int SensorValue3;                                          // Store value from photoresistor (0-1023)

// Variables will change:
int buttonState[] = {0, 0, 0, 0};      // current state of the button1
int lastButtonState[] = {0, 0, 0, 0};  // previous state of the button1
int buttonPushCounter[] = {0, 0, 0, 0};

void setup() {
  // initialize the button pin as a input:
  pinMode(buttonPin[0], INPUT);
  pinMode(buttonPin[1], INPUT);
  pinMode(buttonPin[2], INPUT);
  pinMode(buttonPin[3], INPUT);
  pinMode(buttonPin[4], INPUT);
  pinMode(pResistor[0], INPUT);
  pinMode(pResistor[1], INPUT);
  pinMode(pResistor[2], INPUT);
  pinMode(echoPin, INPUT);

  // initialize the LED as an output:
  pinMode(ForwardPin, OUTPUT);
  pinMode(ReversePin, OUTPUT);
  pinMode(trigPin, OUTPUT);


  // initialize serial communication:
  Serial.begin(9600);
}

void loop() {
  // read the pushbutton input pin:
  buttonState[0] = digitalRead(buttonPin[0]);
  buttonState[1] = digitalRead(buttonPin[1]);
  buttonState[2] = digitalRead(buttonPin[2]);
  buttonState[3] = digitalRead(buttonPin[3]);


  if (buttonState[0] != lastButtonState[0]) {
    if (buttonState[0] == HIGH) {
      buttonPushCounter[0]++;
    }
  }
  if (buttonState[1] != lastButtonState[1]) {
    if (buttonState[1] == HIGH) {
      buttonPushCounter[1]++;
    }
  }
  if (buttonState[2] != lastButtonState[2]) {
    if (buttonState[2] == HIGH) {
      buttonPushCounter[2]++;
    }
  }
  if (buttonState[3] != lastButtonState[3]) {
    if (buttonState[3] == HIGH) {
      buttonPushCounter[3]++;
    }
  }

  lastButtonState[0] = buttonState[0];                    // save the current state as the last state, for next time through the loop
  lastButtonState[1] = buttonState[1];
  lastButtonState[2] = buttonState[2];
  lastButtonState[3] = buttonState[3];

  if (buttonPushCounter[0] % 2 == 0) {
    digitalWrite(ForwardPin, HIGH);
  }
  if (buttonPushCounter[1] % 2 == 0) {
    digitalWrite(ReversePin, HIGH);
  }

if (buttonPushCounter[2] % 2 == 0 && buttonPushCounter[3] % 2 != 0) {
    PhotoCellCode();

  }
  if (buttonPushCounter[2] % 2 != 0 && buttonPushCounter[3] % 2 == 0) {
    UltrasonicCode();
  }
}


void PhotoCellCode() {
  SensorValue1 = analogRead(pResistor[0]);                  //get the value from input pin 1
  SensorValue2 = analogRead(pResistor[1]);
  SensorValue3 = analogRead(pResistor[2]);

  if (SensorValue1 < 300 && SensorValue2 < 300)            //if two are dark turn motor off
  {
    digitalWrite(ForwardPin, LOW);
    digitalWrite(ReversePin, LOW);                                                                          // stop reverse
  }
  if (SensorValue1 < 300 && SensorValue3 < 300)
  {
    digitalWrite(ForwardPin, LOW);
    digitalWrite(ReversePin, LOW);                                                                          // stop reverse
  }
  if (SensorValue2 < 300 && SensorValue3 < 300)
  {
    digitalWrite(ForwardPin, LOW);
    digitalWrite(ReversePin, LOW);                                                                          // stop reverse
  }
  else
  {
    digitalWrite(ForwardPin, HIGH);
    //else, keep the motor on
  }
}

void UltrasonicCode() {
  digitalWrite(trigPin, LOW);                             //Set trigger pin low
  delayMicroseconds(20);                                  //Let signal settle
  digitalWrite(trigPin, HIGH);                            //Set trigPin high
  delayMicroseconds(15);                                  //Delay in high state
  digitalWrite(trigPin, LOW);                             //ping has now been sent
  delayMicroseconds(10);                                  //Delay in high state

  pingTime = pulseIn(echoPin, HIGH);                      //pingTime in microceconds
  pingTime = pingTime / 1000000;                          //convert pingTime to seconds by dividing by 1000000 (microseconds in a second)
  targetDistance = speedOfSound * pingTime;               //Set targetdistance value (in cm)
  targetDistance = targetDistance / 2;                    //Remember ping travels to the target and back from the target, so you must divide by 2 for actual target distance.
  delay(250);

  if ( targetDistance >= 10 ) {                           // Stop motor if too close
    digitalWrite(ForwardPin, LOW);
    digitalWrite(ReversePin, LOW);
  }
  else {
    digitalWrite(ForwardPin, HIGH);

  }
}


I've tried rewriting certain things differently such as writing:

Code: [Select]


buttonPushCounter[0]++;                                       // METHOD ONE
buttonPushCounter[0] = buttonPushCounter[0] + 1;  //METHOD TWO



and adding additional && statements to the last bit like I have for the void photocell and void ultrasonic loops but it doesn't seem to work. Am I missing something obvious here in my code? Or should I just scrap this and try to move everything to a state machine with multiple pushbuttons as inputs?

BasicJoel

OH and I almost forgot! I decided to get rid of my "stop" button and instead just connect that button to the reset pin so when its pressed it simply resets the arduino code...

Maybe thats too simple a solution but it works!

lastchancename

#12
Oct 23, 2019, 12:07 am Last Edit: Oct 23, 2019, 12:08 am by lastchancename
While that may not be what we'd aim for, the good thing is that it resets the device to a consistent known state.
Experienced responders have a nose for laziness, (they were beginners once)... Sure, there are trolls, chest-beaters, and pretenders - but the help you'll get here is about as good as it gets - if you try to help youself!.

TomGeorge

#13
Oct 23, 2019, 12:23 pm Last Edit: Oct 23, 2019, 12:23 pm by TomGeorge
Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
How have you got your buttons wired?

Thanks... Tom... :)
Everything runs on smoke, let the smoke out, it stops running....

MorganS

Code: [Select]
  if (buttonPushCounter[0] % 2 == 0) {
    digitalWrite(ForwardPin, HIGH);
  } else {
    digitalWrite(ForwardPin, LOW);
  }
"The problem is in the code you didn't post."

Go Up