DIY

 

Hardware

Below is the wiring instructions for attaching the photo resistors to the track segments.(hot glue is suggested)

 

 

 

 

Once the photo resistors are in place, you can combine the track pieces.

Open Source Software Installation

Arduino

  • Unzip the library and copy the “arduino” folder into the “libraries” sub-folder of your Processing Sketchbook. (You can find the location of your Sketchbook by opening the Processing Preferences. If you haven’t made a “libraries” sub-folder, create one.)
  • Run Arduino, open the Examples > Firmata > StandardFirmata sketch, and upload it to the Arduino board.Configure Processing for serial:

Processing

  • Download appropriate version from here.

Arduino Code

Compile and upload the code to the Arduino board

Arduino Code

int flag_1 = 0;
int flag_2 = 0;
int time = 0;
float time_centi;
unsigned long startTime;

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  int sensor1 = analogRead(A0);
  int sensor2 = analogRead(A1);
  int sensor3 = analogRead(A2);
  int sensor4 = analogRead(A3);

    if (sensor1 > (sensor2+200))
  {
    flag_1 = 0;

  }

    if (sensor2 > (sensor1 + 200))
  {
    flag_1 = 1;

   }

     if (sensor4 > (sensor3+200))
  {
    flag_2 = 1;
  }

    if (flag_1==1)
  {
      startTime = millis();
  }

    if (flag_2==1)
  {
    time = millis() - startTime;
    delay(2000);
  }

    if (time > 0)
    {
      time_centi = time/10;
      if(time_centi < 256)
      {
        Serial.print(int(time_centi),BYTE);
      }

    }

      time=0;
      flag_1=0;
      flag_2=0;
}

 Processing Code-Retrieve Times

Verify and run processing code

Processing Code-Timer

import processing.serial.*;
float val;
Serial myPort;  // Create object from Serial class
float time_sec;

void setup()
{

  String portName = "COM6";
  myPort = new Serial(this, portName, 9600);
  myPort.bufferUntil('\n');
  size(640,480);
  smooth();
  frameRate(30);
  PFont f = createFont("Arial", 200);
  textFont(f);
  size(500, 500);
}

void draw() {
  if (myPort.available() >0)
  {
    val = myPort.read();
    time_sec = val/100;
    println(time_sec);
    fill(#000000);
    text(time_sec, 40, 200);
  }

}

Processing Code – Graphical Calculator

Insert the Number Box class into the Graphic Calculator code, verify, and run.

Graphic Calculator

Number Box Class

numberBox a,b,c,d,e,f,g,j;

PFont font;

int countmax = 200;
int counts = 0;

float w = 800;
float h = 600;
float [] o = {0,0,0,0,0,0,0,0,0,0};
//float [] c = {0,0,0,0,0,0,0,0,0,0};

String[] nresponse = {"","","","","","","","",""};
String lastInput = new String();

void setup() {
  size(int(w),int(h));
  font = loadFont("Arial-Black-48.vlw");
  a = new numberBox(170,140, 100,50); //Distance
  b = new numberBox(600,160,100,50); //correct answer
  c = new numberBox(170,200,100,50);  //Time 260 100
  d = new numberBox(600,60,100,50);  //Name input
  e = new numberBox(170,60,100,50); //Hypothesis
  f = new numberBox(170,260,100,50); //Speed 200 100
 // g = new numberBox(170, 280,100,50);
  j = new numberBox(3.6*w/10,6*h/10,100,50);
}

void draw() {
  background(200);
  stroke(100);
  strokeWeight(3);
  //line(3*w/10+100,1.925*h/10,1.65*w/10+100,1.925*h/10);
  //line(1.65*w/10+100,1.925*h/10,1.65*w/10+100,1.925*h/10+50);
  textSize(20);
  fill(100);
  text("Player Number:",400,90);
//  text("Hover your mouse over a box to enter numbers.",10,500);
//  text("If the box is orange, the program is reading your input.",10,530);
  text("Hypothesis",30,90);
  text("ft/sec" , 290, 90);
  text("Distance", 45,175);
  text("ft",290, 175);
  text("    Time", 45, 240);
  text("seconds",290, 240);
  text("Speed (ft/sec)", 16, 300);
  text("ft/sec", 290, 300);

int value = 0;
fill(204, 102, 0);
  rect(400,160,170,50);

  fill(204, 102, 0);
  rect(400,220,170,50);

  fill(255, 255, 255);
 text("Calculate", 430,193);

 fill(255, 255, 255);
 text("Clear", 455,253);

  a.display(nresponse[0],0.3,a.o);
  d.display(nresponse[3],0.3,d.o);
  e.display(nresponse[4],0.3, e.o);
  f.display(nresponse[5],0.3,f.o);
 // g.display(nresponse[6]),0.3);
//  j.display(float(nresponse[7]),0.3);

  a.mouseMoved();
  c.mouseMoved();
  d.mouseMoved();
  e.mouseMoved();
  f.mouseMoved();
//  g.mouseMoved();
//  j.mouseMoved();
 // a.o = 1;
  o[0] = a.o;
  o[1] = b.o;
  o[2] = c.o;
  o[3] = d.o;  //
  o[4] = e.o;
  o[5] = f.o;
 // o[6] = g.o;
  o[7] = j.o;

  b.display(nresponse[1],0.3,1);
  c.display(nresponse[2],0.3,o[2]);

  //println(int(float(lastInput)));
  if (int(float(lastInput)) > 0) {
      nresponse[3] = str(int(nresponse[3])-1);
      if (int(float(lastInput)) == int(nresponse[2])/int(nresponse[1])){
        nresponse[3] = str(int(nresponse[3])+2);
      }
      println(int(lastInput));
      println(int(nresponse[1])/int(nresponse[2]));
      nresponse[1] = str(int(random(1,10)));
      nresponse[2] = str(int(nresponse[1])*int(random(1,10)));
      nresponse[4] = str(0);
      nresponse[5] = str(0);
      //counts = 0;
  }
    if (float(nresponse[1]) > 0) {
     if (float(nresponse[1])!=(float(nresponse[5]))) {                                                         //If the answer is WRONG
    println("WooOOOps");
    textSize(30);
    text("That answer doesn't seem correct, try again", 10, 450);
    textSize(40);
    }
    }

  if (float(nresponse[1]) == (float(nresponse[5]))) {                                                         //If the answer is correct, display Correct!
    println("YAY");
    text("Correct! Add 5 points to your score", 50, 500);
  /*if (counts > countmax) {
    counts = 0;
    nresponse[1] = str(int(random(1,10)));
    nresponse[2] = str(int(nresponse[1])*int(random(1,10)));
    nresponse[3] = str(int(nresponse[3])-1);
    nresponse[4] = str(0);
    nresponse[5] = str(0);
  }*/

 if (abs(float(nresponse[4])-(float(nresponse[1]))) < .25){
   textSize(30);
   text("Add 1 Bonus point for an accurate Hypothesis!", 40, 550);
 textSize(40);

 /* if (int(nresponse[3]) == 10) {
    fill(100);
    rect(0,0,w,h);
    textSize(40);
    fill(255);
    text("Good work!",w/2,h/2);
    delay(1000);
    nresponse[3] = "";
  }*/
  counts++;
  lastInput = "";

}
}
}
void mousePressed(){
  if(mouseX >400 && mouseX <570 && mouseY >160 && mouseY<210) {
    nresponse[1] = str(float(nresponse[0])/float(nresponse[2]));                                         //MATH EQUATION SHIT
  }
  if(mouseX >400 && mouseX <570 && mouseY >220 && mouseY<270) {
    nresponse[1] = " ";                                                                                   //CLEAR BUTTON
      nresponse[0] = " ";
      nresponse[2] = " ";
      nresponse[3] = " ";
      nresponse[4] = " ";
      nresponse[5] = " ";
  }
}

void keyPressed() {
   for (int i = 0; i<8;i++) {

     if (o[i]==1) {
       if (key >= '0' && key <= '9') {
         nresponse[i]+=char(key);
         if (abs(float(nresponse[i]))>float(100)){
           nresponse[i] = nresponse[i].substring(0,nresponse[i].length()-1);
         }
       }
       else if(key == '.') {
         nresponse[i]+=char(key);
         if (abs(float(nresponse[i]))>float(100)){
           nresponse[i] = nresponse[i].substring(0,nresponse[i].length()-1);
         }
       }
       else if(key == ENTER || key == RETURN)
       {
         lastInput = nresponse[i] = nresponse[i] + key;
         nresponse[i] = "";
       }
       else if(key == BACKSPACE && nresponse[i].length() > 0)
       {
         nresponse[i] = nresponse[i].substring(0, nresponse[i].length() - 1);
       }
     }
     if (key == '+') {
       countmax += 10;
       println("+");
     }
     if (key == '-') {
       countmax -= 10;
       println("-");
     }
   }
}

And number box class to be included.

//fraction class
class numberBox {
  int a = 0;
  float x, y; //x coordinate, y coordinate of centroid
  float w, h; //width specification, height specification
  float o;      //The mouse is over the body part
  float c;      //The mouse clicks
  float n = 1;
  PFont font;

  //Constructor
  numberBox(float xpos, float ypos, float wn, float hn) {
    x = xpos;
    y = ypos;
    w = wn;
    h = hn;
    font = loadFont("Arial-Black-48.vlw");
  }

 void mouseMoved() {
    if ((mouseX >= (x)) && (mouseX <= (x + w)) && (mouseY >= (y)) && (mouseY <= (y + h))) {
      o = 1;
    }
    else {
      o = 0;
    }
  }

  float mousePressed() {
    if (mousePressed && (o == 1)) {
      c = 1;
    }
    else {
      c = 0;
    }
    return c;
  }

  void display(String q, float p, float selected) {
    rectMode(CORNER);
    fill(255,selected*255+100);
    stroke(0);
    strokeWeight(4);
    rect(x, y, w, h);
    fill(0);
    textFont(font,32*screen.height*0.8/800);
    text(q,x-w*p+w/2,y+h/4+h/2);
    fill(100,a);
    strokeWeight(1);
    float u = q.length()*40;
    u = constrain(u, 0, w-w/30);
    if (o == 1) {
      rect(x+u,y,w/30,h);
      a += 3;
      if (a >250) {
        a = 100;
      }
    }

  }

}