The original code worked fine on a nano, but when I'm attempting to switch it to the esp I just can't seem to get it right....I've tried several pin variations (which has been very confusing) and with the one here it doesn't work with the buttons but 1 motor turns on with the reset button on the board! What am I doing wrong?? Please help!
////
//////arduino ESP8266 NodeMCU CP2102 ESP-12E with L298n
//////2 push button with 2 motor, single direction
//////push for on, release for off
//////1 potentiameter speed control for both motors
//////
////push button A pin GPIO13 (D1) white input
////push button B pin GPIO15 (D8) purple input
////
////motor 1 En-A GPIO14(D5) orange pwm
////motor 1 int1 GPIO04(D2) green
////motor 1 int2 GPIO13(D7) purple
////
////motor 2 En-B GPIO12(D6) yellow pwm
////motor 2 int3 GPIO02 (D4) brown
////motor 2 int4 GPIO0(D3) blue
//
//potentiometer pin A0 2 yellow analog input
#define enA D5
#define in1 D2
#define in2 D7
const int buttonPinA = D1;
#define enB D6
#define in3 D4
#define in4 D3
const int buttonPinB = D8;
// variables will change:
int buttonStateA = 0; // variable for reading the pushbutton status
// variables will change:
int buttonStateB = 0; // variable for reading the pushbutton status
// Speed control potentiometers
int SpeedControl1 = A0;
int SpeedControl2 = A0;
// Motor Speed Values - Start at zero
int MotorSpeed1 = 0;
int MotorSpeed2 = 0;
void setup() {
pinMode(enA, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(buttonPinA, INPUT);
pinMode(enB, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
pinMode(buttonPinB, INPUT);
}
void loop() {
// Read the values from the potentiometers
MotorSpeed1 = analogRead(SpeedControl1);
MotorSpeed2 = analogRead(SpeedControl2);
// Convert to range of 0-255
MotorSpeed1 = map(MotorSpeed1, 0, 1023, 0, 255);
MotorSpeed2 = map(MotorSpeed2, 0, 1023, 0, 255);
// Adjust to prevent "buzzing" at very low speed
if (MotorSpeed1 < 8)MotorSpeed1 = 0;
if (MotorSpeed2 < 8)MotorSpeed2 = 0;
// Set the motor speeds
analogWrite(enA, MotorSpeed1);
analogWrite(enB, MotorSpeed2);
// Set Motor A forward
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
// read the state of the pushbutton value:
buttonStateA = digitalRead(buttonPinA);
if (buttonStateA == HIGH) {
// turn motor A on:
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
delay(20);
} else {
// turn motor A off:
} digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
delay(20);
// Set Motor B forward
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
// If button is pressed - turn motor on
// read the state of the pushbutton value:
buttonStateB = digitalRead(buttonPinB);
if (buttonStateB == HIGH) {
// turn Motor B on:
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
delay(20);
} else {
// turn Motor B off:
} digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
delay(20);
}