print("Du trykkede på knappen") button1Timer.start() buttonPressed = True elif buttonPressed and button1Timer.started: button1Timer.stop() print("Du holdte knappen nede i 2 sekunder!") buttonDefused = True won = True break if not button1.buttonCheck() and buttonPressed: button1Timer.stop() buttonPressed = False print("Du trykker ikke længere på knappen") if time.time() - timeGameStarted >= gameDuration * 60: won = False break # ellers overarbejder processoren time.sleep(0.001) buzzer.off() led1.off() if won: print("Du har vundet") display.setText("BOMB DEFUSED") else: print("Du har tabt") display.setText("BOMB EXPLODED")
temperatureSensor.read() if temperatureSensor.valid: # Save the Temperature Sensor results in a Temperature Data Object temperatureData["deviceID"] = deviceID temperatureData["temperature"] = temperatureSensor.temperatureF temperatureData["humidity"] = temperatureSensor.humidity temperatureData["pressure"] = 0 # Print results to the console if in debug mode if debug: print("Sampled at %s Temperature: %.2f F Humidity: %.2f" % (str(datetime.datetime.now()), temperatureData["temperature"], temperatureData["humidity"])) # Convert the Temperature Data Object to JSON string strj = json.dumps(temperatureData, ensure_ascii=False) # POST the JSON results to the RESTful Web API using HTTP Basic Authentication response = requests.post(webApiUrl, strj, headers={'Content-Type':'application/json'}, auth=(webApiUsername, webApiPassword)) if response.status_code == 200: strj = response.json() print("Response status is %s with message of %s" % (strj["status"], strj["message"])) else: print("Response Error: %d" % response.status_code) else: print("Temperature Sensor Error") # Turn LED OFF led.off() # Sleep until we need to read the sensors again time.sleep(sampleTime)
def all_off(self): for _, LED in self.list.items(): LED.off()