merging code

part 2

And this code:

/*
 To unlock Door for 5 seconds:
 http://your-IP-address/$1
 
 To turn on alarm for 2 seconds:
 http://your-IP-address/$2
 */

#include <SPI.h>
#include <Ethernet.h>

boolean incoming = 0;

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDA, 0x02 };
IPAddress ip(192,168,1,177); //<<< ENTER YOUR IP ADDRESS HERE!!!

// Initialize the Ethernet server library
// with the IP address and port you want to use 
// (port 80 is default for HTTP):
EthernetServer server(80);

void setup()
{
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);

  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.begin(9600);
}

void loop()
{
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        // 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
        
        //reads URL string from $ to first blank space
        if(incoming && c == ' '){ 
          incoming = 0;
        }
        if(c == '

and I want those two pieces of code all in one so I can put it all on one arduino uno, so if you can help me in any way possible that would be awesome, thanks in advance.){
         incoming = 1;
       }
       
       //Checks for the URL string $1 or $2
       if(incoming == 1){
         Serial.println(c);
         
         if(c == '1'){
           Serial.println("Unlocking Door for 5 Seconds");
           digitalWrite(5, HIGH);
           delay(5000);
           digitalWrite(5, LOW);
         }
         if(c == '2'){
           Serial.println("Turning on Alarm");
           digitalWrite(6, HIGH);
           delay(2000);
           digitalWrite(6, LOW);
         }
       
       }

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(1);
   // close the connection:
   client.stop();
 }
}


and I want those two pieces of code all in one so I can put it all on one arduino uno, so if you can help me in any way possible that would be awesome, thanks in advance.

For starters, you need to post both pieces of code you're proposing to combine...

Have a look at this simple merge demo

...R

and I want those two pieces of code all in one

What would you like the resulting code to do? Until you define that, you are wasting your time.

I cant post the code because it says "The message exceeds the maximum allowed length (9000 characters)." so i'm going to leave the two pieces of code that i want to put together as an attachment

It said I ran out of characters and that i can only use 9000 or something like that. This is the first part of the second code.

This code is for my RFID Door lock and its working both pieces of code are working but I need them to work together, there is no pin conflict I just want it so when I enter the url in my browser it will unlock the door on pin5 for 5 seconds. Sorry for not having both pieces of code posed

RFID_Door_Lock_working_.ino (20.1 KB)

ArduinoWebServer.ino (2.27 KB)

Why do you have Serial.begin() in loop()?

Why
does
all
of
your
code
start
in
column
one?

Why are you calling Serial.end()?

What is the problem with combining the code? Check if there is a client. If there is, deal with it. Check if there is an RFID tag. If there is, deal with it.

for ( i = 0; i < 10; i++ ) // First we need to convert the array above into a 5 HEX BYTE array
{
if ( (val[i] >= '0' ) && ( val[i] <= '9' ) ) // Convert one char to HEX
{
val[i] = val[i] - '0';
} 
else if ( (val[i] >= 'A' ) && ( val[i] <= 'F' ) ) 
{
val[i] = 10 + val[i] - 'A';
}

This is incredibly hard to read. Do yourself a favour and start indenting your code.

This isn't my code o got it from a DIY project

Wizkid288:
This isn't my code o got it from a DIY project

Then I suggest you use the demo code as a basis for writing your own code - code that you can understand.

...R

Some of those forums don't enforce code tags (hint). Then when you copy code from them it is all crappy.

You can fix yours up by using the Autoformat tool in the IDE.