Digigurdy-baz
Loading...
Searching...
No Matches
Public Member Functions | List of all members
GearCrank Class Reference

#include <gearcrank.h>

Public Member Functions

 GearCrank (int v_pin, int buzz_pin)
 GearCrank controls the cranking mechanism on geared-crank gurdies. More...
 
void beginPolling ()
 Begins ADC sampling of the crank's voltage pin. More...
 
void detect ()
 Determines if the crank is connected or not. More...
 
bool isDetected ()
 Reports whether or not there is a crank attached. More...
 
void refreshBuzz ()
 Samples the buzz knob and determines if buzzing started and/or is continuing. More...
 
void update ()
 Samples the crank voltage. More...
 
bool startedSpinning ()
 Reports if spinning has started this update() cycle. More...
 
bool stoppedSpinning ()
 Reports if spinning has sotpped this update() cycle. More...
 
bool isSpinning ()
 Reports if spinning is happening. More...
 
bool startedBuzzing ()
 Reports if buzzing has begun. More...
 
bool stoppedBuzzing ()
 Reports if buzzing has stopped. More...
 

Constructor & Destructor Documentation

◆ GearCrank()

GearCrank::GearCrank ( int  v_pin,
int  buzz_pin 
)

GearCrank controls the cranking mechanism on geared-crank gurdies.

Parameters
v_pinThe analog pin connected to the crank
buzz_pinThe analog pin of the buzz knob potentiometer
Warning
A BuzzKnob object using buzz_pin is a hidden private member object of GearCrank.

Member Function Documentation

◆ beginPolling()

void GearCrank::beginPolling ( )

Begins ADC sampling of the crank's voltage pin.

HIGH_SPEED continuous sampling is being used here. This is very fast (readings are available on-deman, no delay), but ties up one of the ADCs full-time.

Warning
This is hard-coded to use adc0.

◆ detect()

void GearCrank::detect ( )

Determines if the crank is connected or not.

This takes advantage of the fact that analog pin voltage "wanders" without some resistance on it. Calculating the standard deviation of a series of readings determines if crank is conntected/attached.

Warning
Physically moving the crank can create false negative detections.

◆ isDetected()

bool GearCrank::isDetected ( )

Reports whether or not there is a crank attached.

Returns
True if detected, false if not detected

◆ isSpinning()

bool GearCrank::isSpinning ( )

Reports if spinning is happening.

Returns
True if the crank is spinning (whether or not it started this cycle), false otherwise.

◆ refreshBuzz()

void GearCrank::refreshBuzz ( )

Samples the buzz knob and determines if buzzing started and/or is continuing.

Performs a simple greater-than comparison between the crank's voltage and the knob.

◆ startedBuzzing()

bool GearCrank::startedBuzzing ( )

Reports if buzzing has begun.

Returns
True if buzzing started this cycle, false otherwise.

◆ startedSpinning()

bool GearCrank::startedSpinning ( )

Reports if spinning has started this update() cycle.

Returns
True if the crank began spinning this cycle, false otherwise.

◆ stoppedBuzzing()

bool GearCrank::stoppedBuzzing ( )

Reports if buzzing has stopped.

Returns
True if buzzing stopped this cycle, false otherwise.

◆ stoppedSpinning()

bool GearCrank::stoppedSpinning ( )

Reports if spinning has sotpped this update() cycle.

Returns
True if the crank stopped spinning this cycle, false otherwise.

◆ update()

void GearCrank::update ( )

Samples the crank voltage.

  • Actually takes several hundred rapid continuous readings, averages this, and then averages that with the previous reading.

Also subtracts the average voltage detected during crank detection as a form of noise reduction.


The documentation for this class was generated from the following files: