Internet of Things/Testprogramma Poseidon: verschil tussen versies
Naar navigatie springen
Naar zoeken springen
(Nieuwe pagina aangemaakt met ' == Testprogramma poseidon == <syntaxhighlight lang="Python"> </syntaxhighlight>') |
Geen bewerkingssamenvatting |
||
Regel 3: | Regel 3: | ||
<syntaxhighlight lang="Python"> | <syntaxhighlight lang="Python"> | ||
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") | |||
</syntaxhighlight> | </syntaxhighlight> |
Versie van 3 jun 2015 13:57
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")