SHARE
TWEET

Grove Pi Temperature Measure

a guest Dec 3rd, 2019 101 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import grovepi.GrovePi;
  2. import grovepi.Pin;
  3. import grovepi.sensors.*;
  4. import java.lang.Math;
  5.  
  6. public class temp {
  7.    
  8.    
  9.     public static void main(String[] args){
  10.        
  11.         GrovePi grovePi = new GrovePi();
  12.            
  13.         ButtonSensor button = grovePi.getDeviceFactory().createButtonSensor(Pin.DIGITAL_PIN_4);
  14.         TemperatureAndHumiditySensor temp =
  15.         grovePi.getDeviceFactory().createTemperatureAndHumiditySensor(Pin.ANALOG_PIN_0);
  16.        
  17.         double setTemperature = 0;
  18.        
  19.         boolean setTemp = true;
  20.         boolean waitTemp = false;
  21.         double value;
  22.  
  23.         while(setTemp){
  24.             while(button.isPressed()){
  25.            
  26.                 setTemperature = grovePi.analogRead(Pin.ANALOG_PIN_0);
  27.                 System.out.println("Current Temperature: " + setTemperature);
  28.                 setTemp = false;
  29.                 waitTemp=true;
  30.             }
  31.         }
  32.        
  33.         while(waitTemp){
  34.            
  35.             value = grovePi.analogRead(Pin.ANALOG_PIN_0);
  36.             System.out.println("Temperature cooling...");
  37.            
  38.             if(value == setTemperature){
  39.                 System.out.println("Your Drink has reached your perfect temperature: " + setTemperature);
  40.                 waitTemp = false;
  41.                 setTemp = true;
  42.             }
  43.         }
  44.     }
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top