Semester assignments for the course "Microprocessors and Peripherals" of THMMY in AUTH university.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
861 B

#!/usr/bin/python
from redBlocks import *
def enableCallback(sc, interface, value):
if sc.SBO("EnableCoolingSystem").getValue():
print( "Cooling system enabled" )
else:
print( "Cooling system disabled" )
scf = SimulatorConnectionFactory()
scf.registerSBO("EnableCoolingSystem", enableCallback)
scf.registerAI("Temperature Sensor")
scf.registerDO("Cooling System Actor")
sc = scf.create()
sc.SBO("EnableCoolingSystem").setValue(True)
while (True):
sc.lock()
if sc.isSimulationRunning() and sc.SBO("EnableCoolingSystem").getValue():
temperature = sc.AI("Temperature Sensor").getValue()
if sc.DO("Cooling System Actor").getValue():
temperature -= 3
if temperature < 0:
temperature = 0
else:
temperature += 1
if temperature > 255:
temperature = 255
sc.AI("Temperature Sensor").setValue(temperature)
sc.unlock()
sleep(0.5)