Bi-Directional
#include "cubelet.h"
{
}
{
unsigned int motor_speed;
if (block_value < 128){
motor_speed = 2 * (127 - block_value);
}
else {
motor_speed = 2 * (block_value - 128);
}
set_drive(motor_speed);
}
uint8_t weighted_average(void)
Calculates a block value based on the on the weighted average of neighbors block values.
void setup()
Function ran just a single time. Used for setting up variables or timers.
Definition bargraph.c:3
void loop()
The loop() function gets called repeatedly while a Cubelet is powered on.
Definition bargraph.c:8
#define FORWARD
Definition motor.h:14
#define BACKWARD
Definition motor.h:19
Easer
#include "cubelet.h"
#define BUF_SIZE 8
uint8_t block_values[BUF_SIZE] = {0};
uint8_t counter = 0;
{
}
{
counter++;
if (counter >= BUF_SIZE) counter = 0;
int current_running_average = 0;
for (unsigned int i=0; i<BUF_SIZE; i++){
current_running_average += block_values[i];
}
current_running_average /= BUF_SIZE;
set_drive(current_running_average);
}
void wait(uint16_t delay)
Function to delay execution for a specified amount of time.
Quiver
#include "cubelet.h"
#include <stdbool.h>
bool motor_forward = true;
{
}
{
if (motor_forward) {
motor_forward = false;
}
else {
motor_forward = true;
}
set_drive(block_value);
wait(100+3*(255-block_value));
}
Reverse
#include "cubelet.h"
{
}
{
set_drive(block_value);
}
Scurry
#include "cubelet.h"
#include <stdbool.h>
bool is_moving = false;
{
}
{
if (is_moving){
if (rand()%255 > current_weighted_average){
is_moving = false;
}
}
else {
if (rand()%255 < current_weighted_average){
is_moving = true;
}
}
if (is_moving) set_drive(255);
else set_drive(0);
}