Wiring Forum
http://wiring.org.co/cgi-bin/yabb/YaBB.pl
Programming Questions & Help >> Integration >> Wiring + Flash + Serial
http://wiring.org.co/cgi-bin/yabb/YaBB.pl?num=1189927008

Message started by mga on 09/16/07 at 07:16:45

Title: Wiring + Flash + Serial
Post by mga on 09/16/07 at 07:16:45
Hi

I am new using Wiring along with your Flash serial port found in http://people.interaction-ivrea.it/h.barragan/flashserialinterface.html . I want to control the board from an Adobe Flash visual interface. I am trying a hello-world-like example with three LEDs. I have different buttons in Flash that will send different combinations of 1 and 0 to turn the LEDs on and off in "1,0,1E" format where the "E" is a marker for the last character (I use a last character marker because in the future the amount of characters I will send will be unknown).

The code works the first time I send the data (the first sendMessage("0,1,0E")). The msg variable remains empty all time forward. This is the code:


int led1 = 0;
int led2 = 2;
int led3 = 4;
int led_ = 48;
String msg = "";
boolean done = false;

void setup () {
 Serial.begin(19200);
 pinMode(led1,OUTPUT);
 pinMode(led2,OUTPUT);
 pinMode(led3,OUTPUT);
 pinMode(led_,OUTPUT);
}

void loop () {
 if (Serial.available()>0) {
   Serial.println("stuff to read");
   char letter;
   while (!done) {
     if (Serial.available()>0) {
       Serial.print("reading:");
       letter = Serial.read();
       if (letter != -1 && letter != 'E' ) {
         Serial.print("appended:");
         msg.append(letter);
       } else {
         Serial.print("not appended:");
         done = true;
       }
       Serial.println(letter);
     }
   }
 } else {
   digitalWrite(led_,HIGH);
 }
 if (done) {
   done = false;
   Serial.print("message: ");
   Serial.println(msg);
   char estado1 = msg.charAt(0);
   char estado2 = msg.charAt(2);
   char estado3 = msg.charAt(4);
   if (estado1=='1') {
     digitalWrite(led1,HIGH);
   } else {
     digitalWrite(led1,LOW);
   }
   if (estado2=='1') {
     digitalWrite(led2,HIGH);
   } else {
     digitalWrite(led2,LOW);
   }
   if (estado3=='1') {
     digitalWrite(led3,HIGH);
   } else {
     digitalWrite(led3,LOW);
   }
   digitalWrite(led_,LOW);
   msg = "";
   delay(1000);
  }
}

Wiring Forum » Powered by YaBB 2.5 AE!
YaBB Forum Software © 2000-2010. All Rights Reserved.