int analogPin1 = A5;
int analogPin2 = A4;
int raw = 0;
int Vin = 5;
int redLed = 8;
int greenLed = 12;
float Vout = 0;
float R1 = 1000;
float R2 = 0;
float R3 = 1000;
float R4 = 0;
float buffer = 0;
void setup()
{
Serial.begin(9600);
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
}
void loop()
{
raw = analogRead(analogPin1);
if(raw){
buffer = raw * Vin;
Vout = (buffer)/1024.0;
buffer = (Vin/Vout) - 1;
R2= R1 * buffer;
Serial.print("Vout: ");
Serial.println(Vout);
Serial.print("R2: ");
Serial.println(R2);
delay(1000);
raw = analogRead(analogPin2);
if(raw){
buffer = raw * Vin;
Vout = (buffer)/1024.0;
buffer = (Vin/Vout) - 1;
R4= R3 * buffer;
Serial.print("Vout: ");
Serial.println(Vout);
Serial.print("R4: ");
Serial.println(R4);
delay(1000);
if(R2 == 1503.67)
digitalWrite(redLed, HIGH);
}
}
}
I understand this code is a bit redundant as I have two of the same known values, a third other resistor, and the pot. Basically what is happening is that its reading two analog values at once and prints them. I tossed in a quick function to try and get the LED to work but it does not work at the moment. Like I said, I know this is a bit cumbersome but it is helping me understand what is going on a bit better. Any insight would be appreciated.
