Cubelets API Documentation 2.0
C API
Loading...
Searching...
No Matches
speaker_default.c File Reference

This C file provides a simple program for controlling a Cubelet speaker.

#include "cubelet.h"

Functions

void setup ()
 A placeholder for any initialization logic required before the main loop starts. This function is currently empty but can be expanded to include setup tasks such as initializing hardware or variables.
 
void loop ()
 Repeatedly executes the robot's logic in two stages: thinking (think()) and acting (act()). Usage: Called continuously after setup() finishes. Forms the main operational cycle of the Cubelet.
 
void think ()
 Computes the block_value by using the weighted_average() function. Usage: Updates the global variable block_value, which is used in the act() function.
 
void act ()
 Uses the computed block_value to set the Cubelet's speaker output. Usage: Calls set_speaker(), a function likely provided by the cubelet.h library, to control the Cubelet's speaker based on the current block_value.
 

Function Documentation

◆ setup()

void setup ( )

Function ran just a single time. Used for setting up variables or timers.

void setup()
{
}
void setup()
Function ran just a single time. Used for setting up variables or timers.
Definition bargraph.c:3

◆ loop()

void loop ( )

The loop() function gets called repeatedly while a Cubelet is powered on.

void loop()
{
think();
act();
}
void act()
Using to perform an action based on a previously calculated block value.
Definition bargraph.c:19
void think()
Used in Action and Think Cubelets to calculate their block value.
Definition bargraph.c:14
void loop()
The loop() function gets called repeatedly while a Cubelet is powered on.
Definition bargraph.c:8

◆ think()

void think ( )

Used in Action and Think Cubelets to calculate their block value.

void think()
{
block_value = weighted_average();
}
uint8_t weighted_average(void)
Calculates a block value based on the on the weighted average of neighbors block values.

◆ act()

void act ( )

Using to perform an action based on a previously calculated block value.

void act()
{
set_speaker(block_value);
}