Low Sensitivity
#include "cubelet.h"
{
}
{
uint8_t tmp_block_value = get_distance();
if (tmp_block_value < 128){
tmp_block_value = 0;
}
else {
tmp_block_value = (tmp_block_value - 128) * 2;
}
block_value = tmp_block_value;
}
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
Motion
#include "cubelet.h"
#include <math.h>
#define BUF_SIZE 4
#define MOTION_MULTIPLE 10
#define MOTION_OFFSET 1
uint8_t block_values[BUF_SIZE] = {0};
uint8_t last_running_average = 0;
unsigned int counter = 0;
{
uint8_t current_block_value = get_distance();
for (unsigned int i=0; i<BUF_SIZE; i++){
block_values[i] = current_block_value;
}
last_running_average = current_block_value;
}
{
block_values[counter] = get_distance();
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;
int difference = abs(current_running_average - last_running_average);
difference -= MOTION_OFFSET;
difference *= MOTION_MULTIPLE;
if (difference < 0) difference = 0;
else if (difference > 255) difference = 255;
block_value = difference;
last_running_average = current_running_average;
}
void wait(uint16_t delay)
Function to delay execution for a specified amount of time.
Swipe
#include "cubelet.h"
#include <stdbool.h>
#define TRIGGER_VALUE 50
#define RESET_VALUE 10
bool output_value_on = false;
bool trigger_armed = true;
{
}
{
uint8_t current_distance = get_distance();
if (trigger_armed && current_distance >= TRIGGER_VALUE){
output_value_on = !output_value_on;
trigger_armed = false;
}
else if (!trigger_armed && current_distance <= RESET_VALUE){
trigger_armed = true;
}
if (output_value_on) block_value = 255;
else block_value = 0;
}