/*
--------------------------------------------
-------- Begin Initialise Variables --------
--------------------------------------------
*/
//STAGE #1
//define pins
//add code here
int transistor = 2;
int hall_effect_sensor = A0;
//Sensor readings
//add code here
int hall_effect_sensor_volt = 0;
float pendulum_length = 0.30;
int hall_effect_val = 0;
/*--------------------------------------------
-------- End Initialise Variables ----------
--------------------------------------------
*/
/*
----------------------------------
-------- Begin Setup Loop --------
----------------------------------
*/
void setup()
{
// initialize serial communication at 115200 bits per second.
Serial.begin(9600);
//STAGE 2 - pin modes
//add code here
pinMode(transistor, OUTPUT);
pinMode(hall_effect_sensor, INPUT);
//Control solenoid
//add code here
digitalWrite(transistor, LOW);
delay(1000);
digitalWrite(transistor, HIGH);
delay(1000);
digitalWrite(transistor, LOW);
}
/*
-------------------------------
------- End Setup Loop --------
-------------------------------
*/
/*
----------------------------------
-------- Begin Main Loop ---------
----------------------------------
*/
//STAGE 3 - the main loop
void loop()
{
// variables for timing
unsigned long startTime = 0;
//add more code here...
unsigned long currentTime = 0;
unsigned long elapsedTime = 0;
//get start time
//add code here
startTime = millis();
do {
//read Hall effects sensor
//add code here
hall_effect_val = analogRead(hall_effect_sensor);
//get current time
//add code here
currentTime = millis();
//calc elapsed time in milliseconds
//add code here
elapsedTime = (currentTime - startTime);
//Print data back to the computer
//add code here
Serial.print("Elapsed time = ");
Serial.print(elapsedTime);
Serial.print(", Hall Effect = ");
Serial.println(hall_effect_sensor);
delay(1);
} while (elapsedTime <= 10000);
//STAGE 5 - calculate Gravity...
//average_period = something here;
//evaluate gravity
//g = your calculation here: use the sq() and PI
//STAGE 5b - print your answer...
//Serial.print("gravity = ");
delay(10000); //wait for 10 seconds - LEAVE THIS FOR RELOAD TO WORK PROPERLY!
}
/*
----------------------------------
--------- End Main Loop ----------
----------------------------------
*/