hey gang...
ok taking this another step further in my learning/journey....
I wanted to see if I could simple make a 'nicer' front end for this by using Flash.
and also send a bit more data, then just a 1 or 0....
so the idea to have a Flash front end/gui with a slider or stepper to send a value of 0-255.. and then have the Arduino represent that value on a PWM enabled pin.
So we have a few changes.. and a few NEW things. ![]()
1.) the PHP code we used previously has changed a bit.. (needs to be able to handle NEW (dynamic) data being sent to it form the FLASH front end..
(notice the new line declaring a variable from POST data sent from Flash
PHP Script:
<?PHP
$pwmValue=$_POST["pwmValue"];
exec("mode COM3 BAUD=9600 PARITY=N data=8 stop=1 xon=off");
$fp = fopen("com3", "w");
if (!$fp) {
 echo "Not open";
}else {
 sleep(5);
 echo "Open";
 echo $pwmValue;
 fwrite($fp, $pwmValue);
 fclose($fp);
}
?>
(here is the new Arduino code.. same samples posted all over on how to parse multiple digit string using a starting and delimiting character (thanks PaulS.. fo rthe post on read on it)...)
Arduino Code:
#define SOP '<'
#define EOP '>'
bool started = false;
bool ended = false;
char inData[5];
byte index;
int ledPin = 9; // pwm test pin
int newValue = 0;
void setup(){
 Serial.begin(9600);
}
void loop(){
 // Read all serial data available, as fast as possible
 while(Serial.available() > 0){
  char inChar = Serial.read();
  //Serial.println(inChar);
  if(inChar == SOP){
   index = 0;
   inData[index] = '\0';
   started = true;
   ended = false;
  }
  else if(inChar == EOP){
   ended = true;
   break;
  }
  else{
   if(index < 5){
    inData[index] = inChar;
    index++;
    inData[index] = '\0';
   }
  } Â
 }
Â
 // Packet data done..Â
 if(started && ended){
  newValue = atoi(inData);
  analogWrite(ledPin, newValue); Â
  // Reset for the next packet
  started = false;
  ended = false;
  index = 0;
  inData[index] = '\0'; Â
 }
}
You can test what we have here so far.. by itself.. it should work(as is) using the serial monitor from the Arduino IDE.. you can test by wrapping any number from 0-255 between the < and > tags/characters
The last portion of this project was the Flash front end.. which is VERY (very) simple..
I'll upload the .swf as well a source .fla to look at how it was put together.. but the code for the flash side is just this: (nothing more)
ActionScript Code:
//set stepper boundaries
pwmStepper.minimum = 0;
pwmStepper.maximum = 255;
//create load vars instance
var pwmData:LoadVars = new LoadVars();
sendBtn_mc.onRelease = function(){
pwmData.pwmValue = "<"+pwmStepper.value+">";
trace("DATA CHECK: "+pwmData.pwmValue);
pwmData.sendAndLoad("flash_to_phpSerial.php", pwmData, "POST");
}
Feedback..pointers.. anything you got is always appreciated.
thanks
flash_to_php_Arduino.zip (134 KB)