Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Source and Fritzing circuit of the milliampere meter upcycling project
- Loading branch information
1 parent
69ce6d3
commit 01a9c2d
Showing
6 changed files
with
348 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
// A basic everyday NeoPixel strip test program. | ||
|
||
// NEOPIXEL BEST PRACTICES for most reliable operation: | ||
// - Add 1000 uF CAPACITOR between NeoPixel strip's + and - connections. | ||
// - MINIMIZE WIRING LENGTH between microcontroller board and first pixel. | ||
// - NeoPixel strip's DATA-IN should pass through a 300-500 OHM RESISTOR. | ||
// - AVOID connecting NeoPixels on a LIVE CIRCUIT. If you must, ALWAYS | ||
// connect GROUND (-) first, then +, then data. | ||
// - When using a 3.3V microcontroller with a 5V-powered NeoPixel strip, | ||
// a LOGIC-LEVEL CONVERTER on the data line is STRONGLY RECOMMENDED. | ||
// (Skipping these may work OK on your workbench but can fail in the field) | ||
|
||
#include <Adafruit_NeoPixel.h> | ||
#ifdef __AVR__ | ||
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket | ||
#endif | ||
|
||
// Which pin on the Arduino is connected to the NeoPixels? | ||
// On a Trinket or Gemma we suggest changing this to 1: | ||
#define NEOPIXEL_PIN 6 | ||
|
||
// How many NeoPixels are attached to the Arduino? | ||
#define NEOPIXEL_LEDS 32 | ||
|
||
// Declare our NeoPixel strip object: | ||
Adafruit_NeoPixel strip(NEOPIXEL_LEDS, NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800); | ||
// Argument 1 = Number of pixels in NeoPixel strip | ||
// Argument 2 = Arduino pin number (most are valid) | ||
// Argument 3 = Pixel type flags, add together as needed: | ||
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) | ||
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) | ||
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) | ||
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) | ||
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products) | ||
|
||
|
||
// setup() function -- runs once at startup -------------------------------- | ||
|
||
void setup() { | ||
// These lines are specifically to support the Adafruit Trinket 5V 16 MHz. | ||
// Any other board, you can remove this part (but no harm leaving it): | ||
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000) | ||
clock_prescale_set(clock_div_1); | ||
#endif | ||
// END of Trinket-specific code. | ||
|
||
strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED) | ||
strip.show(); // Turn OFF all pixels ASAP | ||
strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255) | ||
} | ||
|
||
|
||
// loop() function -- runs repeatedly as long as board is on --------------- | ||
|
||
void loop() { | ||
// Fill along the length of the strip in various colors... | ||
/* | ||
colorWipe(strip.Color(255, 0, 0), 50); // Red | ||
colorWipe(strip.Color( 0, 255, 0), 50); // Green | ||
colorWipe(strip.Color( 0, 0, 255), 50); // Blue | ||
// Do a theater marquee effect in various colors... | ||
theaterChase(strip.Color(127, 127, 127), 50); // White, half brightness | ||
theaterChase(strip.Color(127, 0, 0), 50); // Red, half brightness | ||
theaterChase(strip.Color( 0, 0, 127), 50); // Blue, half brightness | ||
rainbow(10); // Flowing rainbow cycle along the whole strip | ||
theaterChaseRainbow(50); // Rainbow-enhanced theaterChase variant | ||
*/ | ||
rainbow(5); // Flowing rainbow cycle along the whole strip | ||
} | ||
|
||
|
||
// Some functions of our own for creating animated effects ----------------- | ||
|
||
// Fill strip pixels one after another with a color. Strip is NOT cleared | ||
// first; anything there will be covered pixel by pixel. Pass in color | ||
// (as a single 'packed' 32-bit value, which you can get by calling | ||
// strip.Color(red, green, blue) as shown in the loop() function above), | ||
// and a delay time (in milliseconds) between pixels. | ||
void colorWipe(uint32_t color, int wait) { | ||
for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip... | ||
strip.setPixelColor(i, color); // Set pixel's color (in RAM) | ||
strip.show(); // Update strip to match | ||
delay(wait); // Pause for a moment | ||
} | ||
} | ||
|
||
// Theater-marquee-style chasing lights. Pass in a color (32-bit value, | ||
// a la strip.Color(r,g,b) as mentioned above), and a delay time (in ms) | ||
// between frames. | ||
void theaterChase(uint32_t color, int wait) { | ||
for(int a=0; a<10; a++) { // Repeat 10 times... | ||
for(int b=0; b<3; b++) { // 'b' counts from 0 to 2... | ||
strip.clear(); // Set all pixels in RAM to 0 (off) | ||
// 'c' counts up from 'b' to end of strip in steps of 3... | ||
for(int c=b; c<strip.numPixels(); c += 3) { | ||
strip.setPixelColor(c, color); // Set pixel 'c' to value 'color' | ||
} | ||
strip.show(); // Update strip with new contents | ||
delay(wait); // Pause for a moment | ||
} | ||
} | ||
} | ||
|
||
// Rainbow cycle along whole strip. Pass delay time (in ms) between frames. | ||
void rainbow(int wait) { | ||
|
||
strip.setBrightness(255); // Set BRIGHTNESS to about 1/5 (max = 255) | ||
|
||
// Hue of first pixel runs 5 complete loops through the color wheel. | ||
// Color wheel has a range of 65536 but it's OK if we roll over, so | ||
// just count from 0 to 5*65536. Adding 256 to firstPixelHue each time | ||
// means we'll make 5*65536/256 = 1280 passes through this outer loop: | ||
for(long firstPixelHue = 0; firstPixelHue < 5*65536; firstPixelHue += 256) { | ||
for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip... | ||
// Offset pixel hue by an amount to make one full revolution of the | ||
// color wheel (range of 65536) along the length of the strip | ||
// (strip.numPixels() steps): | ||
int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels()); | ||
// strip.ColorHSV() can take 1 or 3 arguments: a hue (0 to 65535) or | ||
// optionally add saturation and value (brightness) (each 0 to 255). | ||
// Here we're using just the single-argument hue variant. The result | ||
// is passed through strip.gamma32() to provide 'truer' colors | ||
// before assigning to each pixel: | ||
strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue))); | ||
} | ||
strip.show(); // Update strip with new contents | ||
delay(wait); // Pause for a moment | ||
} | ||
} | ||
|
||
// Rainbow-enhanced theater marquee. Pass delay time (in ms) between frames. | ||
void theaterChaseRainbow(int wait) { | ||
|
||
int firstPixelHue = 0; // First pixel starts at red (hue 0) | ||
for(int a=0; a<30; a++) { // Repeat 30 times... | ||
for(int b=0; b<3; b++) { // 'b' counts from 0 to 2... | ||
strip.clear(); // Set all pixels in RAM to 0 (off) | ||
// 'c' counts up from 'b' to end of strip in increments of 3... | ||
for(int c=b; c<strip.numPixels(); c += 3) { | ||
// hue of pixel 'c' is offset by an amount to make one full | ||
// revolution of the color wheel (range 65536) along the length | ||
// of the strip (strip.numPixels() steps): | ||
int hue = firstPixelHue + c * 65536L / strip.numPixels(); | ||
uint32_t color = strip.gamma32(strip.ColorHSV(hue)); // hue -> RGB | ||
strip.setPixelColor(c, color); // Set pixel 'c' to value 'color' | ||
} | ||
strip.show(); // Update strip with new contents | ||
delay(wait); // Pause for a moment | ||
firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames | ||
} | ||
} | ||
} |
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
/** | ||
* \file VintageSoundSensor.ino | ||
* \brief Sensing the sound level and monitoring the intensity with lights and the gauge level | ||
* | ||
* This is part of the Art-a-Tronic Vintage upcycling creations series | ||
* | ||
* \author Enrico Miglino <balearicdynamics@gmail.com> | ||
* \version 1.0 | ||
* \date Aug 2019 | ||
*/ | ||
|
||
#include "globals.h" | ||
|
||
#undef _DEBUG | ||
|
||
int analogValue = 0; ///< Analog value coming from the Sound Sensor | ||
int digitalValue; ///< Digital value coming from the Sound Sensor | ||
|
||
//! Neopixel class instance | ||
Adafruit_NeoPixel strip(NEOPIXEL_LEDS, NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800); | ||
|
||
//! Rainbow control structure | ||
Rainbow rainbowControl; | ||
|
||
/** | ||
* Initialization and setting on startup | ||
* | ||
* Setup the GPIO pins for the audio sensor and the Neopixel class initial settings: | ||
* all pixel off and light intensity to the minimum value | ||
*/ | ||
void setup() | ||
{ | ||
#ifdef _DEBUG | ||
Serial.begin(115200); | ||
#endif | ||
|
||
pinMode(SENSOR_DIGITAL,INPUT); | ||
pinMode(SENSOR_LED,OUTPUT); | ||
|
||
strip.begin(); // Initialize the NeoPixel strip object (REQUIRED) | ||
strip.show(); // Turn OFF all pixels ASAP | ||
strip.setBrightness(LIGHT_MIN); // Set brightness to the minimum value on startup | ||
|
||
// Initialize the rainbow control structure | ||
rainbowControl.intensity = LIGHT_MIN; | ||
rainbowControl.firstPixelHue = 0; | ||
} | ||
|
||
/** | ||
* Main loop function | ||
* | ||
* \note The digitalValue is not used to trigger automatically the value that is triggered everytime the sound | ||
* level goes over the sensor calibration (when the sensor red LED goes off). Here we calculate the | ||
* sound level depending on the analog read and the preset limits. \n | ||
* The digitalValue is considered anyway to force the LED triggering accordingly, but this means that the | ||
* snesor calibration has not been done well. | ||
* Sensor calibration should be done anyway: To calibrate the sensor reglulate the trimmer on the sensor board | ||
* until the calibration red LED goes off or start blinking. This is the expected setting for the sensitivy level | ||
* In case of very high sound incread decrease the sensitivity level to have always an average value of 500-215 | ||
* in the analog read. | ||
*/ | ||
void loop(){ | ||
analogValue = analogRead(SENSOR_ANALOG); | ||
digitalValue = digitalRead(SENSOR_DIGITAL); | ||
|
||
// if(digitalValue == HIGH) { | ||
// // Just trigger the LED | ||
// digitalWrite(SENSOR_LED, HIGH); | ||
// } | ||
// else { | ||
// Check the detected value and trigger the LED accordingly | ||
if(analogValue > SENSOR_SENSITIVITY) { | ||
digitalWrite(SENSOR_LED,HIGH); | ||
} else { | ||
digitalWrite(SENSOR_LED,LOW); | ||
} | ||
// } | ||
|
||
updateIntensity(); | ||
updateRainbowPixel(); | ||
stepRainbow(); | ||
delay(SAMPLE_INTERVAL); // Slight pause so that we don't overwhelm the serial interface | ||
} | ||
|
||
/** | ||
* Update the light intensity accordingly with the last sensor reading | ||
*/ | ||
void updateIntensity() { | ||
|
||
if(analogValue < 520) { | ||
rainbowControl.intensity = LIGHT_MIN; | ||
} else if(analogValue > 540) { | ||
rainbowControl.intensity = LIGHT_MAX; | ||
} else { | ||
rainbowControl.intensity = map(analogValue, 520, 600, LIGHT_MIN, LIGHT_MAX); | ||
} | ||
|
||
#ifdef _DEBUG | ||
Serial.println(rainbowControl.intensity); | ||
// Serial.println(analogValue); | ||
#endif | ||
} | ||
|
||
/** | ||
* Update the main light rainbow pixel hue | ||
* | ||
* Hue of first pixel runs 5 complete loops through the color wheel. | ||
* Color wheel has a range of 65536 but it's OK if we roll over, so | ||
* just count from 0 to 5*65536. Adding 256 to firstPixelHue each time | ||
* means we'll make 5*65536/256 = 1280 passes through this outer loop: | ||
*/ | ||
void updateRainbowPixel() { | ||
rainbowControl.firstPixelHue += 256; | ||
|
||
// Check for the limit and eventually reset the counter | ||
if(rainbowControl.firstPixelHue >= 5*65536) { | ||
rainbowControl.firstPixelHue = 0; | ||
} | ||
} | ||
|
||
/** | ||
* Rainbow cycle along whole strip. | ||
* | ||
* The function executes a single rainbow step, controlled by the Rainbow | ||
* globla structure. The funcion is a single-step event to be interruptable | ||
* inside a more conplex cycle. | ||
*/ | ||
void stepRainbow() { | ||
// Set the intensity accordingly with the last sensor reading | ||
strip.setBrightness(rainbowControl.intensity); | ||
|
||
// Execute a rainbow step | ||
for(int i = 0; i < strip.numPixels(); i++) { // For each pixel in strip... | ||
// Offset pixel hue by an amount to make one full revolution of the | ||
// color wheel (range of 65536) along the length of the strip | ||
// (strip.numPixels() steps): | ||
int pixelHue = rainbowControl.firstPixelHue + (i * 65536L / strip.numPixels()); | ||
// strip.ColorHSV() can take 1 or 3 arguments: a hue (0 to 65535) or | ||
// optionally add saturation and value (brightness) (each 0 to 255). | ||
// Here we're using just the single-argument hue variant. The result | ||
// is passed through strip.gamma32() to provide 'truer' colors | ||
// before assigning to each pixel: | ||
strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue))); | ||
} | ||
strip.show(); // Update strip with new contents | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* \file globals.h | ||
* \brief Global constants and definitions | ||
* | ||
* \author Enrico Miglino <balearicdynamics@gmail.com> | ||
* \version 1.0 | ||
* \date Aug 2019 | ||
*/ | ||
|
||
#include <Adafruit_NeoPixel.h> | ||
#ifdef __AVR__ | ||
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket | ||
#endif | ||
|
||
|
||
struct Rainbow { | ||
int intensity; ///< Light intensity, set accordingly with the last sound level reading | ||
long firstPixelHue; ///< The first pixel hue value of the rainbow rotating sequence | ||
}; | ||
|
||
// Audio sensor constants | ||
#define SENSOR_ANALOG A0 ///< Arduino input pin to accept the Sound Sensor's analog output | ||
#define SENSOR_DIGITAL 3 ///< Arduino input pin to accept the Sound Sensor's digital output | ||
#define SENSOR_LED 4 ///< LED for direct soundsensor feedback | ||
|
||
/** | ||
* The sensor sensitivity level is the Analog value (around the mid of the 10 bits of the AD Arduino port) | ||
* You can set this value accoridngly with the environmental conditions where the sensor should work. | ||
* Alternatively, a potentiometer on analog input A1 can be used to dynamically control the final | ||
* sensitivity level that is the analog level triggering the LED. | ||
*/ | ||
#define SENSOR_SENSITIVITY 520 | ||
|
||
/** | ||
* Delay between two samples. Every cycle between the samplea sueinf wcwey loop cycle. This delay | ||
* is applied to the timed tRainbow funciton that executes one step (with this delay) everytime | ||
* it is called. | ||
*/ | ||
#define SAMPLE_INTERVAL 3 | ||
|
||
//! Neopixel constants | ||
#define NEOPIXEL_PIN 6 ///< Neopixel signal pin | ||
//! Number of Neopixel LEDs in the strip (four sequential 8 LEDs strips) | ||
#define NEOPIXEL_LEDS 32 | ||
//! Minimum light intensity (absolute min = 0) | ||
#define LIGHT_MIN 5 | ||
//! Maximum light intensity (absolute max = 255) | ||
#define LIGHT_MAX 50 |