Go Down

Topic: 03/ Love O Meter - Advanced Exercise - 2 People (Read 769 times) previous topic - next topic

milobits

May 17, 2017, 06:10 pm Last Edit: May 17, 2017, 06:19 pm by milobits
Hi Everyone,

This is my first post and I've just completed project 3 and it works, it's exciting stuff!

But I was wondering if anyone has an idea of how you would make the interface for two people where the little brain icon is at the end of the last page.

I've had the idea to add another sensor and duplicate all the code so that their is sensorPin1 & 2 and so on. When at the if/else statement my idea is that when both people kiss their respective sensors that both lip temperatures should be in the same range and LEDs should light up if they are within the temperature ranges.

Another I thought of would be with just one sensor, the program will take two readings, compare them and if they are within the same range then a separate green or blue or whatever colour LED will light up. I just don't know what the code would look like (this seems better method as there is only one temperature sensor in the kit).

Here is my code for the first idea, if anyone has done this it would be great to see!
I'm not sure if what I did with the comparison code is ok or not though...

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600); // Opens the serial port

for(int pinNumber = 2; pinNumber < 5; pinNumber++){
  pinMode(pinNumber,OUTPUT);
  digitalWrite(pinNumber,LOW);
}

}

void loop() {
  // put your main code here, to run repeatedly:
const int sensorPin1 = A0;
const int sensorPin2 = A1;
const float baselineTemp = 20.3;
int sensorVal1 = analogRead(sensorPin1);
Serial.print("Sensor Value: ");
Serial.print(sensorVal1);

int sensorVal2 = analogRead(sensorPin2);
Serial.print("Sensor Value: ");
Serial.print(sensorVal2);

float voltage1 = (sensorVal1/1024.0) * 5.0; // Get the voltage value from ADC reading
Serial.print(" Volts: ");
Serial.print(voltage1);

float voltage2 = (sensorVal2/1024.0) * 5.0; // Get the voltage value from ADC reading
Serial.print(" Volts: ");
Serial.print(voltage2);

Serial.print(" degrees C: ");
float temperature1 = (voltage1 - .5) * 100;
Serial.println(temperature1);

Serial.print(" degrees C: ");
float temperature2 = (voltage2 - .5) * 100;
Serial.println(temperature2);


// If temperature is less than baseline then LEDs are all off
if(temperature1 < baselineTemp || temperature2 < baselineTemp){
  digitalWrite(2, LOW);
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
} else if(temperature1 >= baselineTemp+2 && temperature1 <= baselineTemp+4 && temperature2 >= baselineTemp+2 && temperature2 <= baselineTemp+4){
  digitalWrite(2, LOW);
  digitalWrite(3, LOW);
  digitalWrite(4, HIGH);
} else if(temperature1 >= baselineTemp+4 && temperature1 <= baselineTemp+6 && temperature2 >= baselineTemp+4 && temperature2 <= baselineTemp+6){
  digitalWrite(2, LOW);
  digitalWrite(3, HIGH);
  digitalWrite(4, HIGH);
} else if(temperature1 >= baselineTemp+6 && temperature1 >= baselineTemp+6){
  digitalWrite(2, HIGH);
  digitalWrite(3, HIGH);
  digitalWrite(4, HIGH);
}
delay(1);
}

Go Up