ok i have two pieces of code that i want to put together, a if statement for if a analouge value get to a certain point it will switch on a LED, but i want the LED to come on and also send the command line in telnet. i have both codes that run perfect seperatly so i tried to combine them but dosnt really do what i want. it might be down to a if/else statement within another if/else statement. here is my code please can you help me
if state ment code
*/
// These constants won’t change:
const int analogPin = A0; // pin that the sensor is attached to
const int ledPin = 9; // pin that the LED is attached to
const int threshold = 400; // an arbitrary threshold level that’s in the range of the analog input
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize serial communications:
Serial.begin(9600);
}
void loop() {
int analogValue = analogRead(analogPin);// read the value of the potentiometer:
if (analogValue > threshold) {
digitalWrite(ledPin, HIGH);// if the analog value is high enough, turn on the LED:
}
else {
digitalWrite(ledPin,LOW);
}
}
telnet code
#include <SPI.h>
#include <Ethernet.h>
byte mac = { 0x90, 0xA2, 0xDA, 0x00, 0x28, 0x67 }; //mac address of arduino
byte ip = { 172, 18, 10, 52 }; //ip address of arduino
byte subnet = {255,255,0,0};
byte gateway = {172, 18, x, x};
byte server = { 172, 18, xx, xx}; //email server of penny and giles
int time = 2000;
int wait = 250;
Client client (server, 25);
void setup()
{
Ethernet.begin(mac, ip, gateway, subnet);
Serial.begin(4800);
delay(time);
Serial.println(“connecting…”);
if (client.connect())
{
Serial.println(“connected”);
client.println(“helo pgxexch01.pag.cw.local” );
delay(wait);
client.println(“MAIL From: joe.winstanley@pennyandgiles.com”);
delay(wait);
client.println(“RCPT To: joe.winstanley@pennyandgiles.com”);
delay(wait);
client.println(“DATA”);
delay(wait);
client.println(“Please let me know it worked”);
client.println(".");
client.println(“QUIT”);
delay(wait);
} else {
Serial.println(“did not connect connection failed”);
}
}
void loop()
{
while (client.available()) {
char c = client.read();
Serial.print(c);
}
if (!client.connected()) {
Serial.println();
Serial.println(“disconnecting.”);
client.stop();
for(;
;
}
}
my combined code
#include <SPI.h>
#include <Ethernet.h>
byte mac = { 0x90, 0xA2, 0xDA, 0x00, 0x28, 0x67 }; //mac address of arduino
byte ip = { 172, 18, 10, 52 }; //ip address of arduino
byte subnet = {255,255,0,0};
byte gateway = {172, 18, x, x};
byte server = { 172, 18, x, xx}; //email server of penny and giles
int time = 2000;
int wait = 250;
const int analogPin = A0; // pin that the sensor is attached to
const int ledPin = 9; // pin that the LED is attached to
const int threshold = 400; // an arbitrary threshold level that’s in the range of the analog input
int analogValue = analogRead(analogPin);// read the value of the potentiometer:
Client client (server, 25);
void setup()
{
pinMode(ledPin, OUTPUT); // initialize the LED pin as an output:
Ethernet.begin(mac, ip, gateway, subnet);
Serial.begin(4800);
delay(time);
Serial.println(“connecting…”);
if (client.connect())
{
label:
if (analogValue > threshold) {
digitalWrite(ledPin, HIGH);// if the analog value is high enough, turn on the LED:
Serial.println(“connected”);
client.println(“helo pgxexch01.pag.cw.local” );
delay(wait);
client.println(“MAIL From: joe.winstanley@pennyandgiles.com”);
delay(wait);
client.println(“RCPT To: joe.winstanley@pennyandgiles.com”);
delay(wait);
client.println(“DATA”);
delay(wait);
client.println(“Please let me know it worked”);
client.println(".");
client.println(“QUIT”);
delay(wait);
}else{
digitalWrite(ledPin,LOW);
goto label;
}
}else{
Serial.println(“did not connect connection failed”);
}
}
void loop()
{
while (client.available()) {
char c = client.read();
Serial.print(c);
}
if (!client.connected()) {
Serial.println();
Serial.println(“disconnecting.”);
client.stop();
for(;
;
}
{ int analogValue = analogRead(analogPin);// read the value of the potentiometer:
}
}