I am trying to run a door open and close function and would like to stack shields I currently run a Seeed motor shield and don't have them stacked they are wired together with some wires crossed. I now have a Arduino motor shield and can only run the motor one way. I have a website with 2 buttons one to open door and one to close door. Here is my code I know I am missing something simple but don't know what to change.
// =====================================================================
// INCLUDES
// =====================================================================
#include <SPI.h>
#include <Ethernet.h>
// =====================================================================
// GLOBAL INITALIZATION
// =====================================================================
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(10,0,1,212); // 1.1.1.2
IPAddress gateway(10,0,1,1);
IPAddress subnet(255,255,255,0);
EthernetServer server(89);
int pinI1 = 6; // define I1 interface
int pinI2 = 7; // define I2 interface
int speedpinA = 3; // enable motor A
int pinI3 = 8; // define I3 interface
int pinI4 = 2; // define I4 interface
int speedpinB = 5; // enable motor B
int runOnce = 0;
int spead = 255; // Motor speed
int downTimer = 2280; // Delay timer in ms
int upTimer = 7000; // Delay timer in ms
// =====================================================================
// SETUP
// =====================================================================
void setup()
{
Serial.begin(9600);
SPI.begin;
Ethernet.begin(mac, ip);
server.begin();
Serial.print("Server Initalized");
pinMode(pinI1,OUTPUT);
pinMode(pinI2,OUTPUT);
pinMode(speedpinA,OUTPUT);
pinMode(pinI3,OUTPUT);
pinMode(pinI4,OUTPUT);
pinMode(speedpinB,OUTPUT);
}
// =====================================================================
// LOOP
// =====================================================================
void loop() {
listenForEthernetClients();
}
// =====================================================================
// SUBROUTINES
// =====================================================================
// ---------------------------------------------------------------------
void listenForEthernetClients() {
// ---------------------------------------------------------------------
EthernetClient client = server.available();
if (client) {
Serial.print("Got a client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
runOnce = 1;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.print(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == 'Z' && runOnce == 1) { // Close Door
Serial.print("Closing Door");
closeDoor();
delay(downTimer);
stop();
Serial.print("Done...");
runOnce = 2;
}
else if (c == 'Y' && runOnce == 1) { // Open Door
Serial.print("Opening Door");
openDoor();
delay(upTimer);
stop();
Serial.print("Done...");
runOnce = 2;
}
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.println("<html>");
client.println("<form method='GET' action=''>");
client.println("<input type='hidden' name='openDoor' value='Y'>");
client.println("<input type='submit' value='Open Door' style=height:220px;width:600px>");
client.println("</form>");
client.println("<form method='GET' action=''>");
client.println("<input type='hidden' name='closeDoor' value='Z'>");
client.println("<input type='submit' value='Close Door' style=height:220px;width:600px>");
client.println("</form>");
client.println("</html>");
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(5);
// close the connection:
client.stop();
}
}
// ---------------------------------------------------------------------
void openDoor()//
// ---------------------------------------------------------------------
{
analogWrite(speedpinA,spead);//input a simulation value to set the speed
analogWrite(speedpinB,spead);
//digitalWrite(pinI4,HIGH);//turn DC Motor B move clockwise
digitalWrite(pinI3,LOW);
digitalWrite(pinI2,HIGH);//turn DC Motor A move clockwise
//digitalWrite(pinI1,LOW);
}
// ---------------------------------------------------------------------
void closeDoor()//
// ---------------------------------------------------------------------
{
analogWrite(speedpinA,spead);//input a simulation value to set the speed
analogWrite(speedpinB,spead);
//digitalWrite(pinI4,LOW);//turn DC Motor B move anticlockwise
digitalWrite(pinI3,HIGH);
digitalWrite(pinI2,LOW);//turn DC Motor A move clockwise
//digitalWrite(pinI1,HIGH);
}
// ---------------------------------------------------------------------
void stop()//
// ---------------------------------------------------------------------
{
digitalWrite(speedpinA,LOW);// Unenble the pin, to stop the motor. this should be done to avid damaging the motor.
digitalWrite(speedpinB,LOW);
delay(1000);
}