Hi, I've set up 2 multiplexers on my Arduino, which I can read via an array, using this script:
//Give convenient names to the control pins
#define CONTROL0 6
#define CONTROL1 5
#define CONTROL2 4
#define CONTROL3 3
#define CONTROL4 11
#define CONTROL5 10
#define CONTROL6 9
#define CONTROL7 8
//Create arrays for data from the the MUXs
int chip1[16];
int chip2[16];
void setup()
{
//Set MUX control pins to output
pinMode(CONTROL0, OUTPUT);
pinMode(CONTROL1, OUTPUT);
pinMode(CONTROL2, OUTPUT);
pinMode(CONTROL3, OUTPUT);
pinMode(CONTROL4, OUTPUT);
pinMode(CONTROL5, OUTPUT);
pinMode(CONTROL6, OUTPUT);
pinMode(CONTROL7, OUTPUT);
//Open the serial port at ? bps
Serial.begin(19200);
}
void loop()
{
//This for loop is used to scroll through and store the 16 inputs on the FIRST multiplexer
for (int i=0; i<16; i++)
{
//The following 4 commands set the correct logic for the control pins to select the desired input
digitalWrite(CONTROL0, (i&15)>>3);
digitalWrite(CONTROL1, (i&7)>>2);
digitalWrite(CONTROL2, (i&3)>>1);
digitalWrite(CONTROL3, (i&1));
//Read and store the input value at a location in the array
chip1[i] = analogRead(1);
}
//This for loop is used to scroll through the SECOND multiplexer
for (int i=0; i<16; i++)
{
digitalWrite(CONTROL4, (i&15)>>3);
digitalWrite(CONTROL5, (i&7)>>2);
digitalWrite(CONTROL6, (i&3)>>1);
digitalWrite(CONTROL7, (i&1));
chip2[i] = analogRead(2);
}
//The following lines are for printing out results of CHIP1
Serial.print("Chip 1: ");
for (int i=0; i<16; i++)
{
Serial.print("-");
Serial.print(chip1[i]);
}
Serial.println();
//The following lines are for printing out results of CHIP2
Serial.print("Chip 2: ");
for (int i=0; i<16; i++)
{
Serial.print("-");
Serial.print(chip2[i]);
}
Serial.println();
}
Now, I'd like to convert that code to run exactly the same in ActionScript 3.
I did some looking up, and made this:
//Give convenient names to the control pins
var CONTROL0:Number=6
var CONTROL1:Number=5
var CONTROL2:Number=4
var CONTROL3:Number=3
var CONTROL4:Number=11
var CONTROL5:Number=10
var CONTROL6:Number=9
var CONTROL7:Number=8
//Create arrays for data from the the MUXs
var chip1:Array=[];
var chip2:Array=[];
void setup() //this isnt proper As3 code, as I'm not sure what to put here
{
//Set MUX control pins to output
arduino.setPinMode(CONTROL0, OUTPUT);
arduino.setPinMode(CONTROL1, OUTPUT);
arduino.setPinMode(CONTROL2, OUTPUT);
arduino.setPinMode(CONTROL3, OUTPUT);
arduino.setPinMode(CONTROL4, OUTPUT);
arduino.setPinMode(CONTROL5, OUTPUT);
arduino.setPinMode(CONTROL6, OUTPUT);
arduino.setPinMode(CONTROL7, OUTPUT);
//Open the serial port at ? bps
Serial.begin(19200);
}
void loop() //this isnt proper As3 code, as I'm not sure what to put here
{
//This for loop is used to scroll through and store the 16 inputs on the FIRST multiplexer
for (int i=0; i<16; i++)
{
//The following 4 commands set the correct logic for the control pins to select the desired input
if (i=>15) { arduino.writeDigitalPin(CONTROL0, 3); }
if (i=>7) { arduino.writeDigitalPin(CONTROL1, 2); }
if (i=>3) { arduino.writeDigitalPin(CONTROL2, 1); }
else { arduino.writeDigitalPin(CONTROL3, 0); }
//Read and store the input value at a location in the array
chip1[i] = arduino.getAnalogData(1);
}
//This for loop is used to scroll through the SECOND multiplexer
for (int i=0; i<16; i++)
{
if (i=>15) { arduino.writeDigitalPin(CONTROL4, 3); }
if (i=>7) { arduino.writeDigitalPin(CONTROL5, 2); }
if (i=>3) { arduino.writeDigitalPin(CONTROL6, 1); }
else { arduino.writeDigitalPin(CONTROL7, 0); }
//Read and store the input value at a location in the array
chip2[i] = arduino.getAnalogData(2);
}
As you can see, the code above won't run as is, in AS3.
Now, can you help me to make it work as it should? All help is welcome!
But how can I get this to run in ActionScript nonstop? (I know, by adding an Enter_Frame function, but to what? the stage?)
Using onReceiveAnalogData is too CPU intensive to run all the time.
The method I used to get Arduino data to Flash, is AS3Glue: Google Code Archive - Long-term storage for Google Code Project Hosting.
Please help me out AS SOON AS POSSIBLE!
Thanks in advance