home > Tales of Grim > Prototype code
Tales of Grim
Project Members
Ji Sun Lee
Jaymes Dec
James Daher
Caleb Clark

 
Prototype code on Arduino
Book code
int storyFirstSensor = 2;   
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
int inByte = 0;         // incoming serial byte


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()
{
  // if we get a valid byte, read analog ins:
  if (Serial.available() > 0) {
    // get incoming byte:
    inByte = Serial.read();

    storyFirstVal = digitalRead(storyFirstSensor);
    storySecondVal = digitalRead(storySecondSensor);
    storyThridVal = digitalRead(storyThirdSensor);
    storyFourthVal = digitalRead(storyFourthSensor); 

    Serial.print(storyFirstVal*255, BYTE);
    Serial.print(storySecondVal*255, BYTE);
    Serial.print(storyThridVal*255, BYTE);
    Serial.print(storyFourthVal*255, BYTE);   


    if (storyFirstVal == 0 && storySecondVal == 255 && storyThridVal == 255 && storyFourthVal == 255) {
      digitalWrite(roomFirstOutput, HIGH);
      digitalWrite(roomSecondOutput, LOW);
      digitalWrite(roomThridOutput, LOW);
      digitalWrite(roomFourthOutput, LOW);
      //Serial.println ("Turning on light in the First Room");
    } else if (storyFirstVal == 255 && storySecondVal == 0 && storyThridVal == 255 && storyFourthVal == 255) {
      digitalWrite(roomFirstOutput, LOW);
      digitalWrite(roomSecondOutput, HIGH);
      digitalWrite(roomThridOutput, LOW); 
      digitalWrite(roomFourthOutput, LOW);
      //Serial.println("Turning on light in the Second Room");
    } else if (storyFirstVal == 255 && storySecondVal == 255 && storyThridVal == 0 && storyFourthVal == 255) {
      digitalWrite(roomFirstOutput, LOW); 
      digitalWrite(roomSecondOutput, LOW);
      digitalWrite(roomThridOutput, HIGH);
      digitalWrite(roomFourthOutput, LOW);
      //Serial.println("Turning on light in the Third Room");
    } else if (storyFirstVal == 255 && storySecondVal == 255 && storyThridVal == 255 && storyFourthVal == 0) {
      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");
    }

  }   
  /*Serial.print(storyFirstSensor, BYTE);
   Serial.print(storySecondSensor, BYTE);
   Serial.print(storyThirdSensor, BYTE);
   Serial.print(storyFourthSensor, BYTE); */
}


Do you want to contact us?
Ji Sun Lee, Jaymes Dec, James Daher, Caleb Clark