Internet of Things/Testprogramma Poseidon

Uit Lab
Naar navigatie springen Naar zoeken springen

Testprogramma poseidon

import time
import grovepi
import grove_barometer_lib

led = 4     # led-relais op grovepi D4 
valve = 3   # klep-relais op grovepi D3
valveOn = 1 # klep aan (initieel)
ledOn = 0   # lamp uit (initeel)

moisturePin = 0 # grovepi A0
# barometer op grovepi I2C-2

grovepi.pinMode(led, "OUTPUT")
grovepi.pinMode(valve, "OUTPUT")

while True:
  try:
    print("hi")
    b = grove_barometer_lib.barometer()
    print("Pressure: " + str(b.pressure) + " temperature: " + str(b.temperature))

    moisture = grovepi.analogRead(moisturePin)
    print("Moisture: " + str(moisture))

    grovepi.digitalWrite(led, ledOn)
    ledOn = 1 - ledOn

    grovepi.digitalWrite(valve, valveOn)
    valveOn = 1 - valveOn
    time.sleep(1)

  except KeyboardInterrupt:
    # reset outputs
    grovepi.digitalWrite(led, 0)
    grovepi.digitalWrite(valve, 0)
    break
  except IOError:
    print("error")