I'm newbie here, sorry! lol!!
#include <stdio.h>
#include <string.h>
int i;
int enablePin = 6;
int address;
int addcomp;
char addressch;
String comrx;
void setup()
{
Serial.begin(19200); // initialize serial at baudrate 9600:
Serial.setTimeout(30); // set serial timeout
pinMode(enablePin, OUTPUT);
pinMode(13, OUTPUT);
pinMode(9, INPUT_PULLUP); // Pin Dip-Switch(1) - address MSB
pinMode(10, INPUT_PULLUP); // Pin Dip-Switch(2)
pinMode(11, INPUT_PULLUP); // Pin Dip-Switch(3)
pinMode(12, INPUT_PULLUP); // Pin Dip-Switch(4) - address LSB
Serial.println("Boot OK");
// convert bits from dip switches to an internal address 0-15
address = byte((!digitalRead(9) * 8) + (!digitalRead(10) * 4) + (!digitalRead(11) * 2) + !digitalRead(12));
Serial.println(address);
Serial.println(address, HEX);
}
void loop() {
if (Serial.available() > 0)
{
comrx = Serial.readStringUntil('\r'); // supposed to receive from COM PORT: "Txx\r" where xx = 00 to 15
Serial.println(comrx);
for (int i = 0; i <= 15; i++) {
char s [10];
sprintf (s, "TO%d", i);
printf (" %4s %4s %4d\n", comrx, s, strcmp (comrx, s));
}
int n;
sscanf (comrx, "TO%d", & n);
printf (" n = %d\n", n);
return 0;
// IF STRING "Txx\r" where xx is the INTERNAL ADDRESS, the unit should report this string out to the COM PORT (RS-485)
if
{
delay(50);
digitalWrite(enablePin, HIGH);
delay(10);
Serial.println("Temp=");
delay(200);
digitalWrite(enablePin, LOW);
}
}
}