Skip to content

Instantly share code, notes, and snippets.

@RQF7
Last active August 19, 2019 04:44
Show Gist options
  • Save RQF7/87b89a3cf21bf2794a77112ea2bb6542 to your computer and use it in GitHub Desktop.
Save RQF7/87b89a3cf21bf2794a77112ea2bb6542 to your computer and use it in GitHub Desktop.
Majority gate with Cubelets
// Program for the wire: a flashlight cube.
#include "cubelet.h"
void setup() {
block_value = 0;
}
void loop() {
if (weighted_average() >= 128) {
set_flashlight(0);
} else {
set_flashlight(255);
}
}
// Program for a brightness cube.
#include "cubelet.h"
void setup() {
block_value = 0;
}
void loop() {
if (get_brightness() > 250)
block_value = 255;
else
block_value = 0;
}
// Program for a distance-sensor cube.
#include "cubelet.h"
void setup() {
block_value = 0;
}
void loop() {
if (get_distance() != 0)
block_value = 255;
else
block_value = 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment