Internet of Things/Testprogramma Poseidon: verschil tussen versies
Naar navigatie springen
Naar zoeken springen
(Nieuwe pagina aangemaakt met ' == Testprogramma poseidon == <syntaxhighlight lang="Python"> </syntaxhighlight>') |
|||
(Een tussenliggende versie door dezelfde gebruiker niet weergegeven) | |||
Regel 1: | Regel 1: | ||
== Testprogramma | == Testprogramma Poseidon == | ||
<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-1 | |||
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> |
Huidige versie van 3 jun 2015 om 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-1
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")