ConnectingDevicesCode
ConnectingDevicesCode
def readFromSensors():
global switchValue # declare switchValue as global
global togglePushButtonValue # declare togglePushButtonValue as global
global potentiometerValue # declare potentiometerValue as global
global flexSensorValue # declare flexSensorValue as global
def writeToActuators():
if (switchValue == HIGH): # evaluates to True if the Switch sensor value is digital HIGH, otherwise false
customWrite(2, 1) # turn on the Light
else:
customWrite(2, 0) # turn off the Light
if (togglePushButtonValue == HIGH): # evaluates to True if the Toggle Push Button sensor value is digital HIGH, otherwise
false
digitalWrite(3, HIGH) # turn on the LED
else:
digitalWrite(3, LOW) # turn off the LED
if (potentiometerValue > 512): # evaluates to True if the Potentiometer is turned at least half way
customWrite(4, HIGH) # turn on the Siren
else:
customWrite(4, LOW) # turn off the Siren
if (flexSensorValue > 0): # evaluates to True if the Flex Sensor is bent, otherwise false
analogWrite(5, flexSensorValue) # turn on the motor with speed equal to the Flex Sensor value
else:
analogWrite(5, 0) # turn off the motor
if __name__ == "__main__": # Evaluates to True if this module is the script being executed, otherwise False if this module is being
imported into another module
main() # call the main function