#include <SPI.h>
#include <Ethernet.h>
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = {
192,168,0,219 };
byte server[] = {
192,168,0,214 };
Client client(server, 8092);
String stringAnswer = "";
int count = 0;
int LEDNUMBER;
int ONOFF;
int length;
void setup() {
// start the Ethernet connection:
Ethernet.begin(mac, ip);
// start the serial library:
Serial.begin(9600);
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.println("connecting...");
// if you get a connection, report back via serial:
if (client.connect()) {
Serial.println("connected");
}
else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
client.println("Arn.Inicio:1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:31:32:33:34:35:36:37:38:39:40:41:42:43:44:45:46:47:48:49:50:51:52:53:54:55:56:57:58:59:60:61:62:63:64:65:66:67:68:69:70:71:72:73:74:75:76:77:78:79:80:81:82:83:84:85:86:87:88:89:90:91:92:93:94:95:96:97:98:99:100:101:102:103:104:105:106:107:108:109:110:111:112:113:114:115:116:117:118:119:120:121:122:123:124:125:126:127:128:129:130:131:132:133:134:135:136:137:138:139:140:141:142:143:144:145:146:147:148:149:150:151:152:153:154:155:156:157:158:159:160:161:162:163:164:165:166:167:168:169:170:171:172:173:174:175:176:177:178:179:180:181:182:183:184:185:186:187:188:189:190:191:192:193:194:195:196:197:198:199:200:201:202:203:204:205:206:207:208:209:210:211:212:213:214:215:216:217:218:219:220:221:222:223:224:225:226:227");
//subscribe
}
void loop(char c)
{
if (client.available()) {
c = client.read();
stringAnswer += c;
count++;
if (count == 11)
{
if (c == '=')
{
length = 13;
}
}
if (count == 12)
{
if (c == '=')
{
length = 14;
}
}
if (count == 13)
{
if (c == '=')
{
length = 15;
}
}
if(count == 13)
{
if (length = 13)
{
Serial.print(stringAnswer);
Serial.println();
LEDNUMBER = stringAnswer.charAt(10);
ONOFF = stringAnswer.charAt(12);
Serial.println();
Serial.print(LEDNUMBER);
Serial.println();
Serial.print(ONOFF);
/* include only when LEDS connected (change PINNUMBER etc... but basically this should work
if (ONOFF == 1)
{
digitalWrite(LEDNUMBER, HIGH);
}
if (ONOFF == 0)
{
digitalWrite(LEDNUMBER, LOW);
}
*/
stringAnswer = "";
count = 0;
LEDNUMBER = 0;
ONOFF = 0;
}
}
if(count == 14)
{
if (length = 14)
{
Serial.print(stringAnswer);
Serial.println();
LEDNUMBER = stringAnswer.charAt(11);
ONOFF = stringAnswer.charAt(13);
Serial.println();
Serial.print(LEDNUMBER);
Serial.println();
Serial.print(ONOFF);
/* include only when LEDS connected (change PINNUMBER etc... but basically this should work
if (ONOFF == 1)
{
digitalWrite(LEDNUMBER, HIGH);
}
if (ONOFF == 0)
{
digitalWrite(LEDNUMBER, LOW);
}
*/
stringAnswer = "";
count = 0;
LEDNUMBER = 0;
ONOFF = 0;
}
}
if(count == 15)
{
if (length = 15)
{
Serial.print(stringAnswer);
Serial.println();
LEDNUMBER = stringAnswer.charAt(12);
ONOFF = stringAnswer.charAt(14);
Serial.println();
Serial.print(LEDNUMBER);
Serial.println();
Serial.print(ONOFF);
/* include only when LEDS connected (change PINNUMBER etc... but basically this should work
if (ONOFF == 1)
{
digitalWrite(LEDNUMBER, HIGH);
}
if (ONOFF == 0)
{
digitalWrite(LEDNUMBER, LOW);
}
*/
stringAnswer = "";
count = 0;
LEDNUMBER = 0;
ONOFF = 0;
}
}
}
// as long as there are bytes in the serial queue,
// read them and send them out the socket if it's open:
while (Serial.available() > 0) {
char inChar = Serial.read();
if (client.connected()) {
client.print(inChar);
}
}
}
Dienstag, 13. September 2011
Arduino to IOCP client
Der folgende Code ist frei verfügbar und gerne zum Wiederverwenden und Modifizieren zu verwenden, nur ein Hinweis auf mich muss erhalten bleiben. Ich konnte ihn noch nicht testen und weiß nicht obs funktioniert und der Anschluss zu den LEDS ist auch noch nicht wirklich implementiert. Ich übernehme keine Haftung für etwaige Schäden.
Abonnieren
Kommentare zum Post (Atom)
Hello
AntwortenLöschenI suggest Admin can set up a forum, so that we can talk and communicate.
Nancy
you can take a look at this forum: http://www.mycockpit.org/forums/showthread.php/23326-Arduino-in-my-cockpit that is the best for flightsimulator - otherwise just send me an email here: x737cockpit "at" gmx. at
AntwortenLöschen