So i am new here, i decided to make a light gate pendulum to measure gravity( shm method), but it wont work really, any ideas on what to do???? im using an i2c bus to connect the arduino unos but it just wont work no matter what i try and do
----------This is the master reader---------
#include <LiquidCrystal.h> // The LCD library
#include <Wire.h> // The i2c bus library
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //Pins used
void setup()
{
lcd.begin(16, 2);
Wire.begin(1);
}
void loop()
{
Wire.requestFrom(2, 96);
recieveEvent();
byte thisArray[2];
lcd.print("The period =");
lcd.print(thisArray[1]);
lcd.setCursor(0, 1);
lcd.print("The value of g =");
lcd.print(thisArray[2]);
}
void recieveEvent()
{
while(Wire.available() >0)
{
for(int p =0; p<2; p++)
{
byte thisArray[p] = Wire.read();
}
}
}
and now for the slave sender
#include <Wire.h>
#include <math.h>
int sensorpin = A0;
void setup()
{
pinMode(12, OUTPUT); // sets the LED at pin 12
double c = 4*(sq(PI)); // declaring the constant 4 pi^2
double L = 48;
Wire.begin(2); // initializes the i2c bus
}
void loop()
{
int val = analogRead(sensorpin);
digitalWrite(12, HIGH);
if(val > 200)
{
do
{
while(val < 200)
{
double T = (micros()/1000);
}
}
double T2 = sq(double T);
double g = (double c)*(double L)/T2;
delay(25);
byte Tp = (byte) T2;
byte gr = (byte) g;
byte test[2] = {Tp, gr};
Wire.write(test, 2);
}