float Vb, Vc, Vin, Ib, Ic, Hfe;
float Rb = 1000, Rc = 47;
int t=0;
int button = 8;     

void setup() {
  // setup
  Serial.begin(9600);
  pinMode(button, INPUT);    
  // make header
  Serial.print("t");
  Serial.print("\t");
  Serial.print("Ib");  
  Serial.print("\t");
  Serial.print("Ic"); 
  Serial.print("\t");
  Serial.println("Hfe"); 
}

void loop() {
  // collect data
  Vb = analogRead(A3); 
  Vc = analogRead(A4);   
  Vin = analogRead(A5); 
  
  // convert to voltages
  Vb=Vb*5/1023;
  Vin=Vin*5/1023;
  Vc=Vc*5/1023;

  //ibase in mA (hence x1000)
  Ib=((Vin-Vb)/Rb)*1000;

  //icol in mA (hence x1000)
  Ic=((5-Vc)/Rc)*1000;

  // hfe ratio so no dimension
  Hfe=Ic/Ib;
  
  // report findings
  t++;
  Serial.print(t);
  Serial.print("\t");
  Serial.print(Ib);  
  Serial.print("\t");
  Serial.print(Ic); 
  Serial.print("\t");
  if (Ib>0){
    Serial.println(Hfe); 
  }
  else{
    Serial.println("overflow"); 
  }
  
  // wait for the user
  while (digitalRead(button) == LOW);
  while (digitalRead(button) == HIGH){
   delay(20);
  } 
}

