Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/instantiations/devday2022-demo-toit

Material used for RIoT Dev Day 2022 Demo
https://github.com/instantiations/devday2022-demo-toit

esp32 toit toit-language

Last synced: 29 days ago
JSON representation

Material used for RIoT Dev Day 2022 Demo

Awesome Lists containing this project

README

        



RIoT Dev Day 2022 Demo



Toit Demo


Material used for [RIoT Dev Day 2022](https://riot.org/event/riot-developer-day-2022/) demo in the [Taking IoT Programming to a Higher Level](https://www.meetup.com/RIoT-NC/events/279446784/) 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](source/traffic-light/traffic-light.toit) and [traffic-light.yaml](source/traffic-light/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

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

## License
- The code is licensed under [MIT](LICENSE).
- The documentation is licensed under [CC BY-SA 4.0](http://creativecommons.org/licenses/by-sa/4.0/).