Skip to content

instantiations/devday2022-demo-toit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RIoT Dev Day 2022 Demo

Toit Demo

Material used for RIoT Dev Day 2022 demo in the Taking IoT Programming to a Higher Level presentation.

Date and Time Logger Demo

Simple demo that prints the Date and Time into the console:

dateAndTime.toit

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 Demo

traffic-light.toit and traffic-light.yaml contain a Toit demo of a physical traffic light.

traffic-light.toit

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

traffic-light.yaml

name: "Traffic Light"
entrypoint: traffic-light.toit
triggers:
  on_boot: true
  on_install: true

License

  • The code is licensed under MIT.
  • The documentation is licensed under CC BY-SA 4.0.

Releases

No releases published

Packages

No packages published