Go Down

Topic: Problem with code (Read 416 times) previous topic - next topic

Ghi102

Hi, I am currently making a ROV with arduino. I am using a code I found on the internet. This is the code:

Code: [Select]
#include <string.h>
#include <Ethernet.h>



byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

byte ip[] = { 192, 168, 1, 110 }; // ip in lan

byte gateway[] = { 192, 168, 1, 1 };

byte subnet[] = { 255, 255, 255, 0 };

Server server(80); 

int ballastfloodpin = 4;

int ballastdrainpin = 2;

int rightbilge = 3;

int leftbilge = 5;

int reversebilge = 7;

int forwardbilge = 9;

int val = 0;

boolean LEDON = false;

String readString = String(30);

void setup(){

Ethernet.begin(mac, ip, gateway, subnet);

pinMode(ballastfloodpin, OUTPUT);

pinMode(ballastdrainpin, OUTPUT);

pinMode(rightbilge, OUTPUT);

pinMode(leftbilge, OUTPUT);

pinMode(reversebilge, OUTPUT);

pinMode(forwardbilge, OUTPUT);

digitalWrite(ballastfloodpin, LOW);

digitalWrite(ballastdrainpin, LOW);

digitalWrite(rightbilge, LOW);

digitalWrite(leftbilge, LOW);

digitalWrite(reversebilge, LOW);

digitalWrite(forwardbilge, LOW);

Serial.begin(9600);


}

void loop(){

Client client = server.available();

if (client) {

while (client.connected()) {

if (client.available()) {

char c = client.read();

if (readString.length() < 30)

{

readString.append(c);

}

if (c == '\n') {

floodstatus();

drainstatus();

rightstatus();

leftstatus();

reversestatus();

forwardstatus();

readString="";

client.stop();

delay(100);

}

}

}

}

}

void htmlcontent(){

Client client = server.available();

client.println("HTTP/1.1 200 OK"); // now output HTML data starting with standart header

client.println("Content-Type: text/html");

client.println();

client.print("<body>");

client.println("<br ><br >");

client.println("</body></html>");

}

void floodstatus(){

if(readString.contains("L=1")) //lets check if LED should be lighted

{

digitalWrite(ballastfloodpin, HIGH); // set the LED on

digitalWrite(ballastdrainpin, HIGH);

Serial.print("DIVE");

}else{

}

}

void drainstatus(){

if(readString.contains("L=2")) //lets check if LED should be lighted

{

digitalWrite(ballastfloodpin, LOW);

digitalWrite(ballastdrainpin, LOW);

Serial.print("SURFACE");

}else{

}

}

void rightstatus(){

if(readString.contains("L=3")) //lets check if LED should be lighted

{

digitalWrite(rightbilge, HIGH); // set the LED on

delay(6000);

digitalWrite(rightbilge, LOW);

Serial.print("RIGHT");

}else{

}

}

void leftstatus(){

if(readString.contains("L=4")) //lets check if LED should be lighted

{

digitalWrite(leftbilge, HIGH); // set the LED on


delay(6000);

digitalWrite(leftbilge, LOW);

Serial.print("LEFT");

}else{


}

}

void reversestatus(){

if(readString.contains("L=5")) //lets check if LED should be lighted

{

digitalWrite(reversebilge, HIGH); // set the LED on

delay(6000);

digitalWrite(reversebilge, LOW);

Serial.print("REVERSE");

}else{

}

}

void forwardstatus(){

if(readString.contains("L=6")) //lets check if LED should be lighted

{

digitalWrite(forwardbilge, HIGH); // set the LED on


delay(6000);

digitalWrite(forwardbilge, LOW);

Serial.print("FORWARD");

}else{

}

}


When I put it in arduino 0022, I get these errors:
Code: [Select]
etch_apr22a.cpp: In function 'void loop()':
sketch_apr22a:101: error: 'class String' has no member named 'append'
sketch_apr22a.cpp: In function 'void floodstatus()':
sketch_apr22a:205: error: 'class String' has no member named 'contains'
sketch_apr22a.cpp: In function 'void drainstatus()':
sketch_apr22a:235: error: 'class String' has no member named 'contains'
sketch_apr22a.cpp: In function 'void rightstatus()':
sketch_apr22a:265: error: 'class String' has no member named 'contains'
sketch_apr22a.cpp: In function 'void leftstatus()':
sketch_apr22a:291: error: 'class String' has no member named 'contains'
sketch_apr22a.cpp: In function 'void reversestatus()':
sketch_apr22a:317: error: 'class String' has no member named 'contains'
sketch_apr22a.cpp: In function 'void forwardstatus()':
sketch_apr22a:343: error: 'class String' has no member named 'contains'


I saw a post on this forum that said that it might solve the problem by using a version older than arduino 0019. I put the same code in arduino 0018. It gave me these errors:
Code: [Select]
java.lang.NullPointerException
at processing.app.debug.Compiler.compile(Compiler.java:75)
at processing.app.Sketch.build(Sketch.java:1412)
at processing.app.Sketch.compile(Sketch.java:1203)
at processing.app.Editor$44.run(Editor.java:1807)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)


Could someone help me understand what is not working in my code, I do not understand the errors I get. Thank you for your help.

PaulS

What is so hard to understand about the message "error: 'class String' has no member named 'append'"?

There is a String class. You are creating an instance of the class:
Code: [Select]
String readString = String(30);
Then, you are trying to call the append() method:
Code: [Select]
readString.append(c);
The string class does not contain a method called append(). It does, however, contained on called concat() that does the same thing that append() used to.

The String class does not contain a method called contains(), either.
Code: [Select]
if(readString.contains("L=1")) //lets check if LED should be lighted
http://arduino.cc/en/Reference/StringObject
Choosing a suitable replacement is left as an exercise in brainpower.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy