| home > Tales of Grim > The final code | ||
|
Tales of Grim |
![]() |
|
| Project
Members Ji Sun Lee Jaymes Dec James Daher Caleb Clark |
||
| The final code Tales of Grim code : Download arduino and flash files (13,625kb, *.zip) Book Arduino code : Sending hi signal to each room, 4 switch and 4 serial out
int storyFirstSensor = 13;
int storySecondSensor = 3;
int storyThirdSensor = 4;
int storyFourthSensor = 5;
int storyFirstVal = 0;
int storySecondVal = 0;
int storyThridVal = 0;
int storyFourthVal = 0;
int roomFirstOutput = 6; // First room
int roomSecondOutput = 7; // Seond room
int roomThridOutput = 8; // Third room
int roomFourthOutput = 12; // Fourth room
void setup()
{
Serial.begin(9600); // use the serial port to send the values back to the computer
pinMode(storyFirstSensor,INPUT);
pinMode(storySecondSensor,INPUT);
pinMode(storyThirdSensor,INPUT);
pinMode(storyFourthSensor,INPUT);
pinMode(roomFirstOutput,OUTPUT);
pinMode(roomSecondOutput,OUTPUT);
pinMode(roomThridOutput,OUTPUT);
pinMode(roomFourthOutput,OUTPUT);
}
void loop()
{
storyFirstVal = digitalRead(storyFirstSensor);
storySecondVal = digitalRead(storySecondSensor);
storyThridVal = digitalRead(storyThirdSensor);
storyFourthVal = digitalRead(storyFourthSensor);
if (storyFirstVal == LOW && storySecondVal == HIGH && storyThridVal == HIGH && storyFourthVal == HIGH) {
digitalWrite(roomFirstOutput, HIGH);
digitalWrite(roomSecondOutput, LOW);
digitalWrite(roomThridOutput, LOW);
digitalWrite(roomFourthOutput, LOW);
Serial.println ("Turning on light in the First Room");
}
else if (storyFirstVal == HIGH && storySecondVal == LOW && storyThridVal == HIGH && storyFourthVal == HIGH) {
digitalWrite(roomFirstOutput, LOW);
digitalWrite(roomSecondOutput, HIGH);
digitalWrite(roomThridOutput, LOW);
digitalWrite(roomFourthOutput, LOW);
Serial.println("Turning on light in the Second Room");
}
else if (storyFirstVal == HIGH && storySecondVal == HIGH && storyThridVal == LOW && storyFourthVal == HIGH) {
digitalWrite(roomFirstOutput, LOW);
digitalWrite(roomSecondOutput, LOW);
digitalWrite(roomThridOutput, HIGH);
digitalWrite(roomFourthOutput, LOW);
Serial.println("Turning on light in the Third Room");
}
else if (storyFirstVal == HIGH && storySecondVal == HIGH && storyThridVal == HIGH && storyFourthVal == LOW) {
digitalWrite(roomFirstOutput, LOW);
digitalWrite(roomSecondOutput, LOW);
digitalWrite(roomThridOutput, LOW);
digitalWrite(roomFourthOutput, HIGH);
Serial.println("Turning on light in the Fourth Room");
}
else {
digitalWrite(roomFirstOutput, LOW);
digitalWrite(roomSecondOutput, LOW);
digitalWrite(roomThridOutput, LOW);
digitalWrite(roomFourthOutput, LOW);
Serial.println("Turning off & on light in all Rooms");
}
}
1st and 2nd Room Arduino code : 2 servo motors and one LED output for the first room, and one servo motor and 2 LED outputs for the second room
// motor with digital switch go! and back!
#define firstSwitchPin 3
#define firstServoPin1 4 // Control pin for servo motor
#define firstServoPin2 5
int firstLedPin1 = 6;
#define secondSwitchPin 7
#define secondServoPin1 8 // Control pin for servo motor
int secondLedPin1 = 9;
int secondLedPin2 = 10;
int secondLedPin3 = 11;
int minPulse = 500; // Minimum servo position
int maxPulse = 2500;
int i = 0;
int j = 0;
int firstState = 0;
int minPulse2 = 500; // Minimum servo position
int maxPulse2 = 2500;
int k = 0;
int m = 0;
int secondState = 0;
long lastPulse = 0; // the time in milliseconds of the last pulse
long lastPulse2 = 0; // the time in milliseconds of the last pulse
void setup() {
pinMode(firstSwitchPin, INPUT);
pinMode(firstServoPin1, OUTPUT); // Set servo pin as an output pin
pinMode(firstServoPin2, OUTPUT);
pinMode(firstLedPin1, OUTPUT);
pinMode(secondSwitchPin, INPUT);
pinMode(secondServoPin1, OUTPUT); // Set servo pin as an output pin
pinMode(secondLedPin1, OUTPUT);
pinMode(secondLedPin2, OUTPUT);
Serial.begin(9600);
}
void loop() {
//////////////////// First story start
firstState = digitalRead(firstSwitchPin);
if(firstState ==1){
i<=2000;
i=i+2;
digitalWrite(firstServoPin1, HIGH); // Turn the motor on
delayMicroseconds(maxPulse-i); // Length of the pulse sets the motor position
digitalWrite(firstServoPin1, LOW); // Turn the motor off
lastPulse = millis(); // save the time of the last pulse
j<=2000;
j=j+20;
digitalWrite(firstServoPin2, HIGH); // Turn the motor on
delayMicroseconds(minPulse+j); // Length of the pulse sets the motor position
digitalWrite(firstServoPin2, LOW); // Turn the motor off
lastPulse = millis(); // save the time of the last pulse
if(j>=2000){
j=0;
digitalWrite(firstServoPin2, HIGH); // Turn the motor on
delayMicroseconds(minPulse+j); // Length of the pulse sets the motor position
digitalWrite(firstServoPin2, LOW); // Turn the motor off
lastPulse = millis(); // save the time of the last pulse
}
Serial.print("Max ");
digitalWrite(firstLedPin1, HIGH); // sets the LED on
} else {
i=0;
j=0;
digitalWrite(firstServoPin1, HIGH); // Turn the motor on
delayMicroseconds(maxPulse+i); // Length of the pulse sets the motor position
digitalWrite(firstServoPin1, LOW); // Turn the motor off
lastPulse = millis();
digitalWrite(firstServoPin2, HIGH); // Turn the motor on
delayMicroseconds(minPulse+j); // Length of the pulse sets the motor position
digitalWrite(firstServoPin2, LOW); // Turn the motor off
lastPulse = millis();
Serial.print("Min ");
digitalWrite(firstLedPin1 , LOW); // sets the LED off
}
//////////////////// First story end
//////////////////// Second story start
secondState = digitalRead(secondSwitchPin);
if(secondState ==1){
k<=2000;
k=k+2;
digitalWrite(secondServoPin1, HIGH); // Turn the motor on
delayMicroseconds(maxPulse2-k); // Length of the pulse sets the motor position
digitalWrite(secondServoPin1, LOW); // Turn the motor off
lastPulse2 = millis(); // save the time of the last pulse
Serial.print("Max ");
digitalWrite(secondLedPin1, HIGH); // sets the LED on
digitalWrite(secondLedPin2, HIGH); // sets the LED on
} else {
k=0;
m=0;
digitalWrite(secondServoPin1, HIGH); // Turn the motor on
delayMicroseconds(maxPulse2+k); // Length of the pulse sets the motor position
digitalWrite(secondServoPin1, LOW); // Turn the motor off
lastPulse2 = millis();
Serial.print("Min ");
digitalWrite(secondLedPin1 , LOW); // sets the LED off
digitalWrite(secondLedPin2 , LOW); // sets the LED off
}
//////////////////// Second story end
}
3rd and 4th Room Arduino code : two LED outputs for the third room, and one DC motor and 3 LED outputs for the 4th room
int redSwitchPin = 2;
int piperSwitchPin = 3;
int piperState = 0;
int piperMotorPin = 6;
int piperLedPin=7;
int piperLedPin2=8;
int redState = 0;
int redLedPin1 = 4;
int redLedPin2 = 5;
void setup() {
//the motor control wires are outputs
pinMode(redSwitchPin, INPUT);
pinMode(piperSwitchPin, INPUT);
pinMode(piperMotorPin, OUTPUT);
pinMode(piperLedPin, OUTPUT);
pinMode(piperLedPin2, OUTPUT);
pinMode(redLedPin1, OUTPUT);
pinMode(redLedPin2, OUTPUT);
}
void loop() {
piperState = digitalRead(piperSwitchPin);
switch (piperState){
case 0:
digitalWrite(piperMotorPin, LOW);
digitalWrite(piperLedPin, LOW);
digitalWrite(piperLedPin2, LOW);
break;
case 1:
digitalWrite(piperMotorPin, HIGH);
digitalWrite(piperLedPin, HIGH);
digitalWrite(piperLedPin2, HIGH);
break;
}
redState = digitalRead(redSwitchPin);
switch (redState){
case 0:
digitalWrite(redLedPin1, LOW);
digitalWrite(redLedPin2, LOW);
break;
case 1:
digitalWrite(redLedPin1, HIGH);
digitalWrite(redLedPin2, HIGH);
break;
}
}
flash Action script code : playing video getting singal from serial port
for (i=0; i<=3; i++) {
this["clip"+i].gotoAndStop(1);
}
myArray = new Array(4);
for (i=0; i<=3; i++) {
myArray[i] = _;
}
resetArray = function () {
for (i=0; i<=3; i++) {
myArray[i] = 0;
}
trace(myArray)
counter = 0;
};
resetArray();
createSocket();
function createSocket() {
///_root.createTextField("inputlabel", 4, 50, 100, 50, 20);
///inputlabel.text = "Input:";
///_root.createTextField("outputlabel", 5, 50, 300, 50, 20);
//outputlabel.text = "Output:";
///_root.createTextField("inputer", 3, 100, 100, 200, 20);
//_root.createTextField("outputer", 2, 100, 300, 200, 20);
//outputer.type = "input";
//outputer.border = true;
///inputer.border = true;
serialServer = new XMLSocket();
trace("made it"+serialServer);
connectionStatus = "made it"+serialServer;
//127.0.0.1 is the same as "localhost" ie an alias to your local machine
//it is concievable to that you would want to connect from another machine and you would change this
serialServer.connect("127.0.0.1", 9001);
serialServer.onConnect = function(success) {
trace("connected "+success);
connectionStatus = "connected "+success;
serialServer.send("HOWDY! FROM FLASH "+new Date().toString());
};
serialServer.onClose = function() {
trace("closed");
connectionStatus = "closed";
};
serialServer.onData = function(data) {
trace("incoming "+data);
resetButtons();
inputer.text = data;
switch (data) {
case "A" :
myArray[counter] = "A";
counter++;
clip0.gotoAndStop(2);
gotoAndStop(2);
break;
case "B" :
myArray[counter] = "B";
counter++;
clip1.gotoAndStop(2);
gotoAndStop(3);
break;
case "C" :
myArray[counter] = "C";
counter++;
clip2.gotoAndStop(2);
gotoAndStop(4);
break;
case "D" :
myArray[counter] = "D";
counter++;
clip3.gotoAndStop(2);
gotoAndStop(5);
break;
}
trace(counter);
trace(myArray);
switch (counter) {
case 4 :
resetArray();
break;
}
};
}
this.onEnterFrame = function(outVar) {
serialServer.send(outputer.text);
outputer.text = "";
};
resetButtons = function () {
for (i=0; i<=3; i++) {
this["clip"+i].gotoAndStop(1);
}
};
|
||
| Do you want to contact us? Ji Sun Lee, Jaymes Dec, James Daher, Caleb Clark |
||