Skip to content

Instantly share code, notes, and snippets.

@gabrieljones
gabrieljones / DistributedCounterDemo.ino
Created December 22, 2020 18:26 — forked from bigjosh/DistributedCounterDemo.ino
Counts the number of connected nodes in a distributed and robust way. More info at https://forum.move38.com/t/yadca-yet-another-distributed-counting-algorithm/468
// SimpleCounter demo
// A simple distributed counter example
//
// On startup, blinks are dim BLUE which shows they are in IDLE mode waiting for a master
//
// Button press a blink to make it master of the cluster. The master will show the current count
// using the 0-342 display format decribed below under showNumber()...
//
// While a blink is actively part of a counting cluster, it will show dim GREEN on the face
// that points to its parent. All parent faces eventually lead back to the master.
// © 2015, 2019 Gabriel Jones
import org.scalajs.dom
import spire.math.Complex
import spire.implicits._
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
val TAU = 2*Math.PI
val LIMIT = 255