Toit Demo
Material used for RIoT Dev Day 2022 demo in the Taking IoT Programming to a Higher Level presentation.
Simple demo that prints the Date and Time into the console:
main:
time := Time.now.local
print "Time: $(%02d time.h):$(%02d time.m)"
print "Date: $(%04d time.year)-$(%02d time.month)-$(%02d time.day)"
traffic-light.toit and traffic-light.yaml contain a Toit demo of a physical traffic light.
import gpio
class TrafficLight:
redLight := gpio.Pin 14 --output
yellowLight := gpio.Pin 27 --output
greenLight := gpio.Pin 12 --output
ON ::= 1
OFF ::= 0
turnAllLightsOn: turnAllLights ON
turnAllLightsOff: turnAllLights OFF
turnAllLights number:
allLights := [redLight, yellowLight, greenLight]
allLights.do: it.set number
printAllLights:
print "Red: $redLight"
print "Yellow: $yellowLight"
print "Green: $greenLight"
runSequence:
turnAllLightsOff
redLight.set ON
sleep --ms=2000
yellowLight.set ON
sleep --ms=1000
redLight.set OFF
yellowLight.set OFF
greenLight.set ON
sleep --ms=2000
greenLight.set OFF
yellowLight.set ON
sleep --ms=1000
yellowLight.set OFF
main:
trafficLight := TrafficLight
2.repeat:
trafficLight.runSequence
name: "Traffic Light"
entrypoint: traffic-light.toit
triggers:
on_boot: true
on_install: true
- The code is licensed under MIT.
- The documentation is licensed under CC BY-SA 4.0.