Documente Academic
Documente Profesional
Documente Cultură
//
// This sketch uses the light sensor built in to Circuit Playground
// to detect the speed (in revolutions per second) of a fidget spinner.
// Load the sketch on a Circuit Playground (either classic or express)
// and notice the first three NeoPixels will turn on bright white.
// Hold a spinning fidget spinner very close to (but not touching) the
// light sensor (look for the eye graphic on the board, it's right
// below the three lit NeoPixels) and look at the serial monitor
// to see it print out the speed of the spinner. This works best
// holding the spinner perpendicular to the sensor, like:
// ||
// || <- Spinner
// ||
// ________ <- Circuit Playground
//
// Author: Tony DiCola
// License: MIT License (https://en.wikipedia.org/wiki/MIT_License)
#include <Adafruit_CircuitPlayground.h>
void setup() {
// Initialize serial monitor at 115200 baud.
Serial.begin(115200);
// Initialize CircuitPlayground library and turn on the first 3 pixels (near the light
sensor)
// to pure white at maximum brightness.
CircuitPlayground.begin(255); // 255 means set pixel colors to max brightness.
CircuitPlayground.clearPixels();
CircuitPlayground.setPixelColor(0, 255, 255, 255); // Set pixel 0, 1, 2 to white.
CircuitPlayground.setPixelColor(1, 255, 255, 255);
CircuitPlayground.setPixelColor(2, 255, 255, 255);
}
void loop() {
// Pause between measurements.
delay(MEASURE_PERIOD_MS);
// Check the amplitude of the signal (difference between min and max)
// is greater than the threshold to continue detecting speed.
uint16_t amplitude = maxval - minval;
if (amplitude < THRESHOLD) {
// Didn't make it past the threshold so start over with another measurement attempt.
return;
}
// Compute midpoint of the signal (halfway between min and max values).
uint16_t midpoint = minval + (amplitude/2);