ARDUINO CODE
This is the website that we downloaded Flash from:
http://memewire.com/reference/Arduino_Flash
/* ------------------------------------------------
* Flash + Arduino LED Tester
* by Jonah Model <jmodel@parsaons.edu>
* modified from ARDUINO CONVERSATION, by beltran berrocal, b@progetto25zero1.com
* ------------------------------------------------ */
int activeLED ; // What LED has Flash requested we turn on? Numbers
2-9, for a total of 8 possible LEDs
int switchState = 0; // What is the current switch state?
int switchState2 = 0;
int switchState3 = 0;
int switchState4 = 0;
int switchState5 = 0;
int lastSwitchState = 0; // Was the switch previously on, or off?
int lastSwitchState2 = 0;
int lastSwitchState3 = 0;
int lastSwitchState4 = 0;
int lastSwitchState5 = 0;
int switchPin = 7; // Which digital i/o pin is setup for the switch?
int switchPin2 = 6;
int switchPin3 = 5;
int switchPin4 = 4;
int switchPin5 = 3;
//----------------------------------------------------------
void setup() {
Serial.begin(19200); //setup serial conversation at 19200 bauds
pinMode(switchPin, INPUT); // sets the switch pin as input
pinMode(switchPin2, INPUT);
pinMode(switchPin3, INPUT);
pinMode(switchPin4, INPUT);
pinMode(switchPin5, INPUT);
for (int i=2; i<=9; i++) {
pinMode(i, OUTPUT); // sets the digital pins 2-9 as output
}
}
void loop () {
//------------------------------------------------------------------------ SWITCH
LOGIC
// get the current state of the switch from our board
switchState = digitalRead(switchPin);
// if the switch has changed states, then let Flash know about it
if (switchState != lastSwitchState) {
if (switchState == 1){
sendStringToFlash("switchoff");
}
else if (switchState == 0){
sendStringToFlash("switchon");
}
}
lastSwitchState = switchState;
switchState2 = digitalRead(switchPin2);
if (switchState != lastSwitchState2) {
if (switchState2 == 1) {
sendStringToFlash("switch2off");
}
else if (switchState2 == 0){
sendStringToFlash("switch2on");
}
}
// now store the state for later comparison
lastSwitchState2 = switchState2;
switchState3 = digitalRead(switchPin3);
if (switchState !=lastSwitchState3) {
if (switchState3 == 1) {
sendStringToFlash("switch3off");
}
else if (switchState3 == 0){
sendStringToFlash("switch3on");
}
}
lastSwitchState3 = switchState3;
switchState4 = digitalRead(switchPin4);
if (switchState !=lastSwitchState4) {
if (switchState4 == 1) {
sendStringToFlash("switch4off");
}
else if (switchState4 == 0){
sendStringToFlash("switch4on");
}
}
lastSwitchState4 = switchState4;
switchState5 = digitalRead(switchPin5);
if (switchState !=lastSwitchState5) {
if (switchState5 == 1) {
sendStringToFlash("switch5off");
}
else if (switchState5 == 0){
sendStringToFlash("switch5on");
}
}
lastSwitchState5 = switchState5;
//------------------------------------------------------------------------ LED LOGIC
// checks if a serial message has arrived to the board
if(Serial.available() > 0) {
//must be a request to light up an LED
//activeLED should be a number 2-9, but in binary it will come in as 50-57
activeLED = Serial.read();
}
if(activeLED >= 50 && activeLED <= 57) {
//a valid LED signal has been received from Flash
// convert the byte to an int - getting ready for digitalWrite()
int outputPort = activeLED-48;
Serial.print("Requesting LED port:");
Serial.println(outputPort);
if(outputPort >= 2 && outputPort <= 9) {
// turns all the LEDs OFF
for (int i=2; i<=10; i++) {
digitalWrite(i,LOW);
}
// then turns your selected LED ON
digitalWrite(outputPort, HIGH);
}
// when we're done, default the activeLED to nothing
activeLED = 0;
}
else if (activeLED) {
Serial.print("Requesting invalid LED port:");
Serial.println(activeLED,BYTE);
}
//slows down the visualization: each sentence will be emitted every .5 seconds
delay(50);
}
//----------------------------------------------------------
/*send to flash
* inspired by D.Mellis printString function. it simply adds the byte(0) at the end
* needed by the XMLSocket to know that the transmission is over.
* read the XMLSocket Actionscript Class documentation for more details
*/
void sendStringToFlash (char *s) {
while (*s) {
printByte(*s++);
}
printByte(0); //notify the XMLSocket that the comunication is over
}