ho fatto un arrocchio con arduino prendendo pezzi qui e la per un menu con lcd , rele' ed dei led ws2812.
mi funziona bene, pero' proprio sul piu ' bello mi dice che ha poca memoria, riesco a fare funzionare 106 led su 112,
ecco il codice
- Codice: Seleziona tutto
#include <Adafruit_NeoPixel.h>
#include <FastLED.h>
#define PIN 13
#define COLOR_ORDER GRB
#define LED_TYPE WS2812B
#define NUM_LEDS 106
#define BRIGHTNESS 100
#define SPEED .20 // Amount to increment RGB color by each cycle
#define BG 0
#define SPARKING 50
#define COOLING 55
#define FRAMES_PER_SECOND 60
#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
#define qsubd(x, b) ((x>b)?wavebright:0) // Digital unsigned subtraction macro. if result <0, then => 0. Otherwise, take on fixed value.
#define qsuba(x, b) ((x>b)?x-b:0) // Analog Unsigned subtraction macro. if result <0, then => 0
int buttonPin = 15; // momentary push button on pin 0
int oldButtonVal = 0;
// FOR SYLON ETC
uint8_t thisbeat = 23;
uint8_t thatbeat = 28;
uint8_t thisfade = 3; // How quickly does it fade? Lower = slower fade rate.
uint8_t thissat = 255; // The saturation, where 255 = brilliant colours.
uint8_t thisbri = 255;
//FOR JUGGLE
uint8_t gHue = 0; // rotating "base color" used by many of the patterns
uint8_t numdots = 4; // Number of dots in use.
uint8_t faderate = 2; // How long should the trails be. Very low value = longer trails.
uint8_t hueinc = 16; // Incremental change in hue between each dot.
uint8_t thishue = 0; // Starting hue.
uint8_t curhue = 0;
uint8_t thisbright = 255; // How bright should the LED/display be.
uint8_t basebeat = 5;
uint8_t max_bright = 255;
// Twinkle
float redStates[NUM_LEDS];
float blueStates[NUM_LEDS];
float greenStates[NUM_LEDS];
float Fade = 0.96;
//Ripple variables
int color;
int center = 0;
int step = -1;
int maxSteps = 16;
float fadeRate = 0.80;
int diff;
//background color
uint32_t currentBg = random(256);
uint32_t nextBg = currentBg;
int myhue = 0;
//One sine demo
uint8_t wavebright = 128; // You can change the brightness of the waves/bars rolling across the screen. Best to make them not as bright as the sparkles.
uint8_t thisrot = 0; // You can change how quickly the hue rotates for this wave. Currently 0.
uint8_t allsat = 255; // I like 'em fully saturated with colour.
bool thisdir = 0; // You can change direction.
int8_t thisspeed = 4; // You can change the speed, and use negative values.
uint8_t allfreq = 32; // You can change the frequency, thus overall width of bars.
int thisphase = 0; // Phase change value gets calculated.
uint8_t thiscutoff = 192; // You can change the cutoff value to display this wave. Lower value = longer wave.
int thisdelay = 25; // You can change the delay. Also you can change the allspeed variable above.
uint8_t bgclr = 0; // A rotating background colour.
uint8_t bgbri = 64;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
int spectrumAvg [7] = { 40, 45, 55, 59, 80, 70, 230};
int boost [7] = { 0, 0, 0, 0, 200, 0, 100};
const int audioOutput = A6; //data out of MSGEQ7
const int strobePin = 15; //strobe on MSGEQ7
const int resetPin = 16; //reset on MSGEQ7
int doubledSpectrumValue[13];
int avg = 0;
int raincolor = 0; //starting point of rainbow
int wait = 0;//8000; //time between modes
int spectrumValue[7]; //array to hold spectrum values
int middle = strip.numPixels() / 2; //address of middle of strand
int length = strip.numPixels() / 7; //splits strand up into 7 sections (7 bands on MGSGEQ7
int eqColors [7][3] = {{255, 0, 0}, {0, 255, 0}, {0, 0, 255}, {120, 120, 0}, {0, 120, 120}, {255, 0, 255}, {255, 255, 255}};
int eqColors2 [7][3] = {{255, 0, 0}, {0, 255, 0}, {0, 0, 255}, {255, 255, 255}, {102, 0, 102}, {255, 0, 127}, {255, 128, 0}};
int intensityColors [3] = {0, 0, 0};
uint32_t beginTime = 0;
uint32_t endTime = 0;
int bright = 1; //select 1 thru 10
int filterValue = 115; // MSGEQ7 always spits out a number around 60, so this filters those out
int global_brightness = 96; // Sets global brightness, i.e. 64 is 1/4 brightness.
int waveSize = 10; // size 4 uses 9 lights. One in the middle, 4 on each side. (time 7 for 63 LEDs total)
//pixels used is (wave size * 2)+1)*7
int maxOverflow = 3;
// Modes
enum
{
} MODE;
bool reverse = true;
int BRIGHTNESS_MAX = 80;
int brightness = 20;
int nPatterns = 16;
int lightPattern = 1;
bool gReverseDirection = false;
CRGB leds[NUM_LEDS];
/* ARDUINO MENU selezionabile con 4 OPZIONI e Display LCD I2C
(Temperatura, Led Verde, Led Rosso, Relè)
Per maggiori info visitate www.progettiarduino.com
Autore Fancello Salvatore
*/
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display
#define ONE_WIRE_BUS 2 // Data wire is plugged into pin 2 on the Arduino
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
#define butUp 11 //pulsante SU al pin 11
#define butDown 10 //Pulsante GIU al pin 10
#define butP 12 //Pulsante SELEZIONA al pin 12
#define butM 9 //non utilizzato in questo esempio
#define alim 7 //Rele' alimentatore pin 8
#define sald 4 //rele' saldatore al pin 7
#define vu 3 //Relè vu meter pin 8
#define plus 8 //Relè vu meter pin 8
#define FAN 6 //IRF520 MOS Driver SUL PIN 6
#define luce 5 //IRF520 MOS Driver SUL PIN 5
int fanSpeed; //VARIABILE VELOCITà VENTOLA
int fanpwm; //VARIABILE PWM
int fanSpeedPercent; //VARIABILE % VELOCITà VENTOLA
int valore;
int impulso;
//Funzioni dei vari cicli
void changeMenu();
void dispMenu();
void mostraMsg();
void alimentatore();
void saldatore();
void vumeter();
void temperatura();
void porta();
void colorWipe();
void colorWipe2();
void ripple();
void one_color_allHSV();
void ripple2();
void FirePurp();
void SineDemo();
void ChangeYou();
void one_sin();
void resetvar();
void sinelon();
void pattern3();
void juggle();
void ChangeMe();
void fireblu();
void fire();
void VuOne();
void VuThree();
void readaudio();
void VuTwo();
void VuSix();
void VuFour();
void VuFive();
void sevenWaves();
void sevenBands();
void nextLed();
void All();
void Off();
void lampa();
//Variabili globali
char menu = 0x01;
char set1 = 0x00, set2 = 0x00 , set3 = 0x00 , set4 = 0x00, set5 = 0x00,set6 = 0x00;
boolean t_butUp, t_butDown, t_butP, t_butM;
void setup() {
FastLED.addLeds<WS2812B, PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
LEDS.addLeds<LED_TYPE, PIN, COLOR_ORDER>(leds, NUM_LEDS);
strip.begin();
strip.setBrightness(255);
strip.show();
pinMode(audioOutput, INPUT);
pinMode(strobePin, OUTPUT);
pinMode(resetPin, OUTPUT);
analogReference(DEFAULT);
digitalWrite(resetPin, LOW);
digitalWrite(strobePin, HIGH);
pinMode(buttonPin, INPUT);
digitalWrite(buttonPin, HIGH); // button pin is HIGH, so it drops to 0 if pressed
lcd.init(); // initialize the lcd
lcd.init();
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("ALIMENTATORE");
delay(500);
for (char i = 9; i < 13; i++) { //Ingresso dei pulsanti
pinMode(i, INPUT_PULLUP);
}
pinMode(luce, OUTPUT);
pinMode(alim, OUTPUT); //LED ROSSO
pinMode(sald, OUTPUT); //LED VERDE
pinMode(vu, OUTPUT); //RELÈ
pinMode(plus, OUTPUT);
digitalWrite (alim, LOW); //Imposto inizialmente il relè allo stato Alto (Attivo)
digitalWrite (sald, LOW);
digitalWrite (vu, LOW);
digitalWrite (plus, LOW);
analogWrite (luce, 240);
t_butUp = 0x00; //Inizializza le variabili come ZERO
t_butDown = 0x00;
t_butP = 0x00;
t_butM = 0x00;
}
void loop() {
sensors.requestTemperatures(); // Send the command to get tem
float TEMP = sensors.getTempCByIndex(0); //VARIABILE FLOTTANTE PER LETTURA TEMPERATURA
if (TEMP < 24) { //SE TEMP è < 23.8 °C LA VENTOLA è FERMA
analogWrite(FAN, 0); // comando pin off
fanSpeed = 0;
}
if ((TEMP >= 24.1) && (TEMP <= 38)) { // setta temp min/max
fanSpeed = map(TEMP, 24, 38, 100, 255);
fanpwm = map(TEMP, 24, 38, 128, 255);
fanSpeedPercent = (TEMP - 24) * 100 / (38 - 24); // Solo per essere sicuri di non avere valori incongruenti
fanSpeedPercent = constrain(fanSpeedPercent, 0, 100);
analogWrite(FAN, fanpwm);
}
changeMenu(); //Menu di scambio
dispMenu(); //Selezionare il menu
}
//Funzioni
void changeMenu() {
if (digitalRead(butUp) == 0x00) { //Setta la variabile in 1 se si preme il pulsante UP
t_butUp = 0x01;
}
if (digitalRead(butDown) == 0x00) { //Setta la variabile in 1 se si preme il pulsante DOWN
t_butDown = 0x01;
}
if (digitalRead(butUp) && t_butUp) {
t_butUp = 0x00;
lcd.clear(); //Cancella Schermo lcd
menu++;
if (menu > 0x06) {
menu = 0x01;
}
}
if (digitalRead(butDown) && t_butDown) {
t_butDown = 0x00;
lcd.clear();
menu--;
if (menu < 0x01) {
menu = 0x06;
}
}
}
void dispMenu() {
switch (menu) {
case 0x01:
temperatura(); //Funzione controllo temperatura
break;
case 0x02:
vumeter(); //Funzione controllo vumeter
break;
case 0x03:
alimentatore(); //Funzione controllo alimentatore
break;
case 0x04:
saldatore(); //Funzione controllo saldatore
break;
case 0x05:
porta (); //Funzione controllo alimentatore
break;
case 0x06:
lampa (); //Funzione controllo alimentatore
break;
}
}
/*Ciclo per la funzione controllo LED1*/
void lampa(){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("luce"); //scrivo su lcd
int buttonVal = digitalRead(12);
if (buttonVal == LOW && oldButtonVal == HIGH) {// button has just been pressed
lightPattern = lightPattern + 1;
}
if (lightPattern > nPatterns) lightPattern = 1;
oldButtonVal = buttonVal;
switch(lightPattern) {
case 1:
VuOne();
break;
case 2:
VuTwo();
break;
case 3:
VuThree();
break;
case 4:
VuFour();
break;
case 5:
VuFive();
break;
case 6:
VuSix();
break;
case 7:
All();
break;
case 8:
SineDemo();
break;
case 9:
ripple();
break;
case 10:
ripple2();
break;
case 11:
sinelon();
break;
case 12:
pattern3();
break;
case 13:
fire();
break;
case 14:
fireblu();
break;
case 15:
FirePurp();
break;
case 16:
Off();
break;
}
}
void alimentatore() {
lcd.clear();
if (digitalRead(alim) == HIGH) { //leggo lo stato del rele' alim
lcd.setCursor(0, 0);
lcd.print("Alimentatore ON"); // scrivo su lcd
}
else {
lcd.print("Alimentatore Off"); // scrivo su lcd
}
if (digitalRead(butP) == 0x00) {
t_butP = 0x01;
}
if (digitalRead(butM) == 0x00) {
t_butM = 0x01;
}
if (digitalRead(butP) && t_butP) {
t_butP = 0x00;
set1++;
if (set1 > 2) {
set1 = 0x01;
}
switch (set1) {
case 0x01:
digitalWrite (alim, HIGH); //attivo rele' alimentatore
break;
case 0x02:
digitalWrite (alim, LOW); //Spengo rele' alimentatore
break;
}
}
}
/*Ciclo per la funzione controllo Relè*/
void vumeter() {
lcd.clear();
lcd.setCursor(0, 0);
if (digitalRead(vu) == HIGH) { //leggo lo stato del rele'
lcd.print("vu ON"); //scrivo su lcd
} else {
lcd.print("vu OOff"); //scrivo su lcd
}
if (digitalRead(butP) == 0x00) {
t_butP = 0x01;
}
if (digitalRead(butM) == 0x00) {
t_butM = 0x01;
}
if (digitalRead(butP) && t_butP) {
t_butP = 0x00;
set2++;
if (set2 > 2) {
set2 = 0x01;
}
switch (set2) {
case 0x01:
digitalWrite (vu, HIGH); //attivo rele' alimentatore
break;
case 0x02:
digitalWrite (vu, LOW); //Spengo rele' alimentatore
break;
}
}
}
/*Ciclo per la funzione controllo TEMPERATURA*/
void temperatura()
{
lcd.setCursor(0, 1);
lcd.print((char)316);
lcd.setCursor(8, 1);
lcd.print((char)767);
lcd.setCursor(15, 1);
lcd.print((char)318);
lcd.setCursor(0, 0);
lcd.print("Temperatura: ");
lcd.setCursor(1, 1);
lcd.print(sensors.getTempCByIndex(0)); // chiamo lettura sensore
lcd.print((char)223);
if (fanSpeedPercent > 9) lcd.print(" ");
lcd.setCursor(10, 1);
if (fanSpeedPercent < 10) lcd.print(" ");
lcd. print(fanSpeedPercent);
}
/*Ciclo per la funzione controllo Led Verde*/
void saldatore() {
lcd.setCursor(0, 0);
if (digitalRead(sald) == HIGH) { //leggo lo stato del rele'
lcd.print("saldatore On "); // srivo su lcd
} else {
lcd.print("saldatore OFF"); //scrivo su lcd
}
if (digitalRead(butP) == 0x00) {
t_butP = 0x01;
}
if (digitalRead(butM) == 0x00) {
t_butM = 0x01;
}
if (digitalRead(butP) && t_butP) {
t_butP = 0x00;
set3++;
if (set3 > 2) {
set3 = 0x01;
}
switch (set3) {
case 0x01:
digitalWrite (sald, HIGH); //attivo rele' alimentatore
break;
case 0x02:
digitalWrite (sald, LOW);
break;
}
}
}
void porta() {
lcd.setCursor(0, 0);
if (digitalRead(plus) == HIGH) { //leggo lo stato del rele' alim
lcd.print("porta ON"); // scrivo su lcd
} else {
lcd.print("porta off"); // scrivo su lcd
}
if (digitalRead(butP) == 0x00) {
t_butP = 0x01;
}
if (digitalRead(butM) == 0x00) {
t_butM = 0x01;
}
if (digitalRead(butP) && t_butP) {
t_butP = 0x00;
set4++;
if (set4 > 2) {
set4 = 0x01;
}
switch (set4) {
case 0x01:
digitalWrite (plus, HIGH); //attivo rele' alimentatore
break;
case 0x02:
digitalWrite (plus, LOW); //Spengo rele' alimentatore
break;
}
}
}
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
void colorWipe2(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
// Pattern 5 - black / off
void Off() {
colorWipe2(strip.Color( 0, 0, 0), 1); // black
strip.show();
}
void ripple() {
if (currentBg == nextBg) {
nextBg = random(256);
}
else if (nextBg > currentBg) {
currentBg++;
} else {
currentBg--;
}
for(uint16_t l = 0; l < NUM_LEDS; l++) {
leds[l] = CHSV(currentBg, 255, 50); // strip.setPixelColor(l, Wheel(currentBg, 0.1));
}
if (step == -1) {
center = random(NUM_LEDS);
color = random(256);
step = 0;
}
if (step == 0) {
leds[center] = CHSV(color, 255, 255); // strip.setPixelColor(center, Wheel(color, 1));
step ++;
}
else {
if (step < maxSteps) {
Serial.println(pow(fadeRate,step));
leds[wrap(center + step)] = CHSV(color, 255, pow(fadeRate, step)*255); // strip.setPixelColor(wrap(center + step), Wheel(color, pow(fadeRate, step)));
leds[wrap(center - step)] = CHSV(color, 255, pow(fadeRate, step)*255); // strip.setPixelColor(wrap(center - step), Wheel(color, pow(fadeRate, step)));
if (step > 3) {
leds[wrap(center + step - 3)] = CHSV(color, 255, pow(fadeRate, step - 2)*255); // strip.setPixelColor(wrap(center + step - 3), Wheel(color, pow(fadeRate, step - 2)));
leds[wrap(center - step + 3)] = CHSV(color, 255, pow(fadeRate, step - 2)*255); // strip.setPixelColor(wrap(center - step + 3), Wheel(color, pow(fadeRate, step - 2)));
}
step ++;
}
else {
step = -1;
}
}
LEDS.show();
delay(50);
}
int wrap(int step) {
if(step < 0) return NUM_LEDS + step;
if(step > NUM_LEDS - 1) return step - NUM_LEDS;
return step;
}
void one_color_allHSV(int ahue, int abright) { // SET ALL LEDS TO ONE COLOR (HSV)
for (int i = 0 ; i < NUM_LEDS; i++ ) {
leds[i] = CHSV(ahue, 255, abright);
}
}
void ripple2() {
if (BG){
if (currentBg == nextBg) {
nextBg = random(256);
}
else if (nextBg > currentBg) {
currentBg++;
} else {
currentBg--;
}
for(uint16_t l = 0; l < NUM_LEDS; l++) {
strip.setPixelColor(l, Wheel(currentBg, 0.1));
}
} else {
for(uint16_t l = 0; l < NUM_LEDS; l++) {
strip.setPixelColor(l, 0, 0, 0);
}
}
if (step == -1) {
center = random(NUM_LEDS);
color = random(256);
step = 0;
}
if (step == 0) {
strip.setPixelColor(center, Wheel(color, 1));
step ++;
}
else {
if (step < maxSteps) {
strip.setPixelColor(wrap(center + step), Wheel(color, pow(fadeRate, step)));
if (step > 3) {
strip.setPixelColor(wrap(center + step - 3), Wheel(color, pow(fadeRate, step - 2)));
}
step ++;
}
else {
step = -1;
}
}
strip.setBrightness(255);
strip.show();
delay(50);
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos, float opacity) {
if(WheelPos < 85) {
return strip.Color((WheelPos * 3) * opacity, (255 - WheelPos * 3) * opacity, 0);
}
else if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color((255 - WheelPos * 3) * opacity, 0, (WheelPos * 3) * opacity);
}
else {
WheelPos -= 170;
return strip.Color(0, (WheelPos * 3) * opacity, (255 - WheelPos * 3) * opacity);
}
}
void FirePurp()
{
// Array of temperature readings at each simulation cell
static byte heat[NUM_LEDS];
// Step 1. Cool down every cell a little
for( int i = 0; i < NUM_LEDS; i++) {
heat[i] = qsub8( heat[i], random8(0, ((COOLING * 10) / NUM_LEDS) + 2));
}
// Step 2. Heat from each cell drifts 'up' and diffuses a little
for( int k= NUM_LEDS - 1; k >= 2; k--) {
heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3;
}
// Step 3. Randomly ignite new 'sparks' of heat near the bottom
if( random8() < SPARKING ) {
int y = random8(7);
heat[y] = qadd8( heat[y], random8(160,255) );
}
// Step 4. Map from heat cells to LED colors
for( int j = 0; j < NUM_LEDS; j++) {
// Scale the heat value from 0-255 down to 0-240
// for best results with color palettes.
byte colorindex = scale8( heat[j], 240);
CRGB color = ColorFromPalette( CRGBPalette16( CRGB::Black, CRGB::Purple, CRGB::Purple, CRGB::White), colorindex);
int pixelnumber;
if( gReverseDirection ) {
pixelnumber = (NUM_LEDS-1) - j;
} else {
pixelnumber = j;
}
leds[pixelnumber] = color;
}
FastLED.show(BRIGHTNESS);
}
void SineDemo() {
ChangeYou(); // Muck those variables around.
EVERY_N_MILLISECONDS(thisdelay) { // FastLED based non-blocking delay to update/display the sequence.
one_sin();
bgclr++;
}
show_at_max_brightness_for_power();
} // loop()
void ChangeYou() {
uint8_t secondHand = (millis() / 1000) % 60; // Increase this if you want a longer demo.
static uint8_t lastSecond = 99; // Static variable, means it's only defined once. This is our 'debounce' variable.
// You can change variables, but remember to set them back in the next demo, or they will stay as is.
if(lastSecond != secondHand) {
lastSecond = secondHand;
switch (secondHand) {
case 0: thisrot = 1; thiscutoff=252; allfreq=8; break; // Both rotating hues
case 5: thisrot = 0; thisspeed=-4; break; // Just 1 rotating hue
case 10: thishue = 255; break; // No rotating hues, all red.
case 15: thisrot = 1; thisspeed=2; break; //
case 20: allfreq = 16; break; // Time to make a wider bar.
case 25: thishue=100; thiscutoff = 96; break; // Change width of bars.
case 30: thiscutoff = 96; thisrot = 1; break; // Make those bars overlap, and rotate a hue
case 35: thisspeed = 3; break; // Change the direction.
case 40: thiscutoff = 128; wavebright = 64; break; // Yet more changes
case 45: wavebright = 128; thisspeed = 3; break; // Now, we change speeds.
case 50: thisspeed = -2; break; // Opposite directions
case 55: break; // Getting complicated, let's reset the variables.
}
}
} // ChangeMe()
void one_sin() { // This is the heart of this program. Sure is short.
// if (thisdir == 0) thisphase+=thisspeed; else thisphase-=thisspeed; // You can change direction and speed individually.
thisphase += thisspeed;
thishue += thisrot; // Hue rotation is fun for thiswave.
for (int k=0; k<NUM_LEDS-1; k++) {
int thisbright = qsubd(cubicwave8((k*allfreq)+thisphase), thiscutoff); // qsub sets a minimum value called thiscutoff. If < thiscutoff, then bright = 0. Otherwise, bright = 128 (as defined in qsub)..
leds[k] = CHSV(bgclr, 255, bgbri);
leds[k] += CHSV(thishue, allsat, thisbright); // Assigning hues and brightness to the led array.
}
} // one_sin()
void resetvar() { // Reset the variable back to the beginning.
wavebright = 128; // You can change the brightness of the waves/bars rolling across the screen. Best to make them not as bright as the sparkles.
thishue = 0; // You can change the starting hue value for the first wave.
thisrot = 0; // You can change how quickly the hue rotates for this wave. Currently 0.
allsat = 255; // I like 'em fully saturated with colour.
thisdir = 0; // You can change direction.
thisspeed = 4; // You can change the speed, and use negative values.
allfreq = 32; // You can change the frequency, thus overall width of bars.
thisphase = 0; // Phase change value gets calculated.
thiscutoff = 192; // You can change the cutoff value to display this wave. Lower value = longer wave.
thisdelay = 25; // You can change the delay. Also you can change the allspeed variable above.
bgbri = 16;
} // resetvar()
void sinelon() {
{
// a colored dot sweeping back and forth, with fading trails
fadeToBlackBy( leds, NUM_LEDS, thisfade);
int pos1 = beatsin16(thisbeat,0,NUM_LEDS);
int pos2 = beatsin16(thatbeat,0,NUM_LEDS);
leds[(pos1+pos2)/2] += CHSV( myhue++/64, thissat, thisbri);
}
FastLED.show();
}
void pattern3() {
ChangeMe();
juggle();
show_at_max_brightness_for_power(); // Power managed display of LED's.
} // loop()
void juggle() { // Several colored dots, weaving in and out of sync with each other
curhue = thishue; // Reset the hue values.
fadeToBlackBy(leds, NUM_LEDS, faderate);
for( int i = 0; i < numdots; i++) {
leds[beatsin16(basebeat+i+numdots,0,NUM_LEDS)] += CHSV(curhue, thissat, thisbright); //beat16 is a FastLED 3.1 function
curhue += hueinc;
}
} // juggle()
void ChangeMe() { // A time (rather than loop) based demo sequencer. This gives us full control over the length of each sequence.
uint8_t secondHand = (millis() / 1000) % 30; // IMPORTANT!!! Change '30' to a different value to change duration of the loop.
static uint8_t lastSecond = 99; // Static variable, means it's only defined once. This is our 'debounce' variable.
if (lastSecond != secondHand) { // Debounce to make sure we're not repeating an assignment.
lastSecond = secondHand;
if (secondHand == 0) {numdots=1; faderate=2;} // You can change values here, one at a time , or altogether.
if (secondHand == 10) {numdots=4; thishue=128; faderate=8;}
if (secondHand == 20) {hueinc=48; thishue=random8();} // Only gets called once, and not continuously for the next several seconds. Therefore, no rainbows.
}
} // ChangeMe()
void fireblu(){
#define FRAMES_PER_SECOND 40
random16_add_entropy( random());
// Array of temperature readings at each simulation cell
static byte heat[NUM_LEDS];
// Step 1. Cool down every cell a little
for( int i = 0; i < NUM_LEDS; i++) {
heat[i] = qsub8( heat[i], random8(0, ((COOLING * 10) / NUM_LEDS) + 2));
}
// Step 2. Heat from each cell drifts 'up' and diffuses a little
for( int k= NUM_LEDS - 1; k >= 2; k--) {
heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3;
}
// Step 3. Randomly ignite new 'sparks' of heat near the bottom
if( random8() < SPARKING ) {
int y = random8(7);
heat[y] = qadd8( heat[y], random8(160,255) );
}
// Step 4. Map from heat cells to LED colors
for( int j = 0; j < NUM_LEDS; j++) {
// Scale the heat value from 0-255 down to 0-240
// for best results with color palettes.
byte colorindex = scale8( heat[j], 240);
CRGB color = ColorFromPalette( CRGBPalette16( CRGB::Black, CRGB::Blue, CRGB::Aqua, CRGB::White), colorindex);
int pixelnumber;
if( gReverseDirection ) {
pixelnumber = (NUM_LEDS-1) - j;
} else {
pixelnumber = j;
}
leds[pixelnumber] = color;
}
FastLED.show(BRIGHTNESS);
}
void fire(){
#define FRAMES_PER_SECOND 40
random16_add_entropy( random());
// Array of temperature readings at each simulation cell
static byte heat[NUM_LEDS];
// Step 1. Cool down every cell a little
for( int i = 0; i < NUM_LEDS; i++) {
heat[i] = qsub8( heat[i], random8(0, ((COOLING * 10) / NUM_LEDS) + 2));
}
// Step 2. Heat from each cell drifts 'up' and diffuses a little
for( int k= NUM_LEDS - 1; k >= 2; k--) {
heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3;
}
// Step 3. Randomly ignite new 'sparks' of heat near the bottom
if( random8() < SPARKING ) {
int y = random8(7);
heat[y] = qadd8( heat[y], random8(160,255) );
}
// Step 4. Map from heat cells to LED colors
for( int j = 0; j < NUM_LEDS; j++) {
// Scale the heat value from 0-255 down to 0-240
// for best results with color palettes.
byte colorindex = scale8( heat[j], 240);
CRGB color = ColorFromPalette( CRGBPalette16( CRGB::Black, CRGB::Red, CRGB::Yellow, CRGB::White), colorindex);
int pixelnumber;
if( gReverseDirection ) {
pixelnumber = (NUM_LEDS-1) - j;
} else {
pixelnumber = j;
}
leds[pixelnumber] = color;
}
FastLED.show(BRIGHTNESS);
}
void VuOne(){
readaudio();
int y=0;
for(int i=0; i<7; i++){
int intensity = map(spectrumValue[i], 0, 900, 0, 9);
for(int j=(length*i); j<(length*(i+1)); j++){
if(intensity > (j-(length*i))){
//strip.setPixelColor(j, strip.Color(eqColors[i][0], eqColors[i][1], eqColors[i][2]));
strip.setPixelColor(y, (Wheel(y*4)));
y++;
}
else{
strip.setPixelColor(j, strip.Color(0,0,0));
}
}
}
strip.setBrightness(100);
strip.show();
}
void VuThree(){
readaudio();
int intensity[7];
int total;
int y=0;
for(int i=0; i<7; i++){
intensity[i] = map(spectrumValue[i], 0, 900, 0, 9);
total+= intensity[i];
}
for(int m=0; m<7; m++){
for(int p=0; p<intensity[m]; p++){
strip.setPixelColor(y, strip.Color(eqColors2[m][0], eqColors2[m][1], eqColors2[m][2]));
//strip.setPixelColor(y, (Wheel(y*4)));
y++;
}
}
for(int k=total; k<strip.numPixels(); k++){
strip.setPixelColor(k, strip.Color(0,0,0));
}
strip.setBrightness(100);
strip.show();
for(int j=0; j<strip.numPixels(); j++){
strip.setPixelColor(j, strip.Color(0,0,0));
}
delay(30);
}
void readaudio(){
digitalWrite(resetPin, HIGH);
digitalWrite(resetPin, LOW);
for(int i=0; i<7; i++){
digitalWrite(strobePin, LOW);
delayMicroseconds(30); //allow output levels to settle
spectrumValue[i]=analogRead(audioOutput) - spectrumAvg[i];
digitalWrite(strobePin, HIGH);
}
}
uint32_t Wheel(byte WheelPos) {
if(WheelPos < 85) {
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}
void VuTwo()
{
digitalWrite(resetPin, HIGH);
digitalWrite(resetPin, LOW);
//Measure the magnitudes of the 7 frequency bins
avg = 0;
for (int i = 0; i < 7; i++){
digitalWrite(strobePin, LOW);
delayMicroseconds(30); // to allow the output to settle
spectrumValue[i] = analogRead(audioOutput);
avg += spectrumValue[i];
digitalWrite(strobePin, HIGH);
}
avg = avg/7;
//Clear out the NeoPixel String
for(int i = 0; i < 60; i++){
strip.setPixelColor(i, strip.Color(0, 0, 0));
}
//Draw the meter on the NeoPixel string
for(int i = 0; i < map(avg, 0, 1023, 0, 60); i++){
strip.setPixelColor(i, strip.Color(i*4, 60 - i, map(spectrumValue[0], 0, 1023, 0, 60))); //Added blue flash for bass hit
//strip.setPixelColor(i, strip.Color(i*4, 60 - i, 0)); //Without blue flash
}
strip.setBrightness(225);
strip.show();
}
void VuSix(){
int i;
int j;
int loopEnd;
int numPixels = strip.numPixels() - 5;
double pixRatio = (float)numPixels / 255;
double channelRatio = pixRatio / 7;
float weight =1;
digitalWrite(resetPin, HIGH);
digitalWrite(resetPin, LOW);
//grabs readings from chip
for (i = 0; i < 7; i++)
{
digitalWrite(strobePin, LOW);
delayMicroseconds(30); // to allow the output to settle
spectrumValue[i] = analogRead(audioOutput);
digitalWrite(strobePin, HIGH);
//weight = 1;
if (i < 3)
weight = 1.5;
else
weight = 1;
//makes 10 bit value 8 bit
spectrumValue[i] /= 4;
spectrumValue[i] = (int)( (double)spectrumValue[i] * (channelRatio * weight) );
if(spectrumValue[i] > 255)
spectrumValue[i] = 255;
}
for (i = 0;i<spectrumValue[0] && i< numPixels; i++)
strip.setPixelColor(i, 255, 0, 0);
loopEnd = i + spectrumValue[1];
for (;i<loopEnd && i< numPixels; i++)
strip.setPixelColor(i,0, 255, 0);
loopEnd = i + spectrumValue[2];
for (;i<loopEnd && i< numPixels; i++)
strip.setPixelColor(i,0,0, 255);
loopEnd = i + spectrumValue[3];
for (;i<loopEnd && i< numPixels; i++)
strip.setPixelColor(i,255, 0,255);
loopEnd = i + spectrumValue[4];
for (;i<loopEnd && i< numPixels; i++)
strip.setPixelColor(i,255, 255, 0);
loopEnd = i + spectrumValue[5];
for (;i<loopEnd && i< numPixels; i++)
strip.setPixelColor(i,255, 128, 0);
loopEnd = i + spectrumValue[6];
for (;i<loopEnd && i< numPixels; i++)
strip.setPixelColor(i,255,255,255);
for(;i<numPixels; i++)
strip.setPixelColor(i,0,0,0);
for (i = numPixels;i>numPixels-spectrumValue[0] && i>0; i--)
strip.setPixelColor(i, 255, 0, 0);
loopEnd = i - spectrumValue[1];
for (;i>loopEnd && i>0; i--)
strip.setPixelColor(i,0, 255, 0);
loopEnd = i - spectrumValue[2];
for (;i>loopEnd && i>0; i--)
strip.setPixelColor(i,0,0, 255);
loopEnd = i - spectrumValue[3];
for (;i>loopEnd && i>0; i--)
strip.setPixelColor(i,255, 0,255);
loopEnd = i - spectrumValue[4];
for (;i>loopEnd && i>0; i--)
strip.setPixelColor(i,255, 255, 0);
loopEnd = i - spectrumValue[5];
for (;i>loopEnd && i>0; i--)
strip.setPixelColor(i,255, 128, 0);
loopEnd = i - spectrumValue[6];
for (;i>loopEnd && i>0; i--)
strip.setPixelColor(i,255,255,255);
strip.show();
}
void VuFour(){
int i = 0, j= 0,k =0;
digitalWrite(resetPin, HIGH);
digitalWrite(resetPin, LOW);
//grabs readings from chip
for (i = 0; i < 7; i++)
{
digitalWrite(strobePin, LOW);
// delayMicroseconds(30); // to allow the output to settle
spectrumValue[i] = analogRead(audioOutput);
digitalWrite(strobePin, HIGH);
//makes 10 bit value 8 bit
spectrumValue[i] /= 4;
if(spectrumValue[i] > 255)
spectrumValue[i] = 255;
if (spectrumValue[i] <= 55)
spectrumValue[i] = 0;
spectrumValue[i] = (int)(spectrumValue[i] / 7);
if (i == 0)
spectrumValue[i] *= 1.5;
else
spectrumValue[i] *= 1.2;
for (j=0; j<27; j++)
{
if (i == 0 && spectrumValue[i] >=j)
strip.setPixelColor(k++,255, 0,0);
else if (i == 1 && spectrumValue[i] >=j)
strip.setPixelColor(k++,0, 255, 0);
else if (i == 2 && spectrumValue[i] >=j)
strip.setPixelColor(k++,0,0, 255);
else if (i == 3 && spectrumValue[i] >=j)
strip.setPixelColor(k++,255, 0, 255);
else if (i == 4 && spectrumValue[i] >=j)
strip.setPixelColor(k++,0, 255,255);
else if (i == 5 && spectrumValue[i] >=j)
strip.setPixelColor(k++,255, 255,0);
else if (i == 6 && spectrumValue[i] >=j)
strip.setPixelColor(k++,255,255,255);
else
strip.setPixelColor(k++,0,0,0);
}
delay(2);
}
strip.show();
}
void VuFive() {
sevenWaves();
}
void sevenWaves(){
int i;
int k;
int tmpVal;
int r;
int g;
int b;
int j;
int x;
int q;
int middlePin;
digitalWrite(resetPin, HIGH);
digitalWrite(resetPin, LOW);
//int overflow[77];
//get readings from chip
for (i = 0; i < 7; i++)
{
digitalWrite(strobePin, LOW);
//delayMicroseconds(30); // to allow the output to settle
spectrumValue[i] = analogRead(audioOutput);
if (i==0)
middlePin = waveSize +1;
else
middlePin = waveSize + 1 + ( (1 + waveSize * 2) * i);
for (k = (middlePin - waveSize); k <= (middlePin + waveSize); k++)
{
int pinOutValue = 0;
int reading;
reading = round( spectrumValue[i]*5 / (600) );
int placeInWave = abs(k - middlePin);
if( reading >= placeInWave)
pinOutValue = 1;
if( spectrumValue[i] < filterValue)
pinOutValue = 0;
if(pinOutValue==1)
pinOutValue = 255;
// RGB for bands 1-7
if(i==0)
{
r = 0; g = 0; b = 255;
}
if(i==1)
{
r = 0; g = 255; b= 0;
}
if(i==2)
{
r = 255; g = 255; b = 0;
}
if(i==3)
{
r = 0; g = 255; b = 0;
}
if(i==4)
{
r = 0; g = 255; b = 255;
}
if(i==5)
{
r = 0; g = 0 ; b = 255;
}
if(i==6)
{
r = 255; g = 0; b = 153;
}
if (pinOutValue == 0)
{
r = 0; g = 0; b = 0;
}
strip.setPixelColor(k-1, r, g, b);
}
digitalWrite(strobePin, HIGH);
}
strip.setBrightness(global_brightness);
strip.show();
}
void sevenBands(){
int i;
digitalWrite(resetPin, HIGH);
digitalWrite(resetPin, LOW);
//grabs readings from chip
for (i = 0; i < 7; i++)
{
digitalWrite(strobePin, LOW);
// delayMicroseconds(30); // to allow the output to settle
spectrumValue[i] = analogRead(audioOutput);
if(spectrumValue[i] < filterValue)
spectrumValue[i] = 0;
spectrumValue[i] = spectrumValue[i] / (1024/255);
if(spectrumValue[i] > 255)
spectrumValue[i] = 255;
digitalWrite(strobePin, HIGH);
}
strip.setPixelColor(0, spectrumValue[6], 0, 0);
strip.setPixelColor(1, spectrumValue[5], 0, 0);
strip.setPixelColor(2, spectrumValue[4], 0, 0);
strip.setPixelColor(3, spectrumValue[3], 0, 0);
strip.setPixelColor(4, spectrumValue[2], 0, 0);
strip.setPixelColor(5, spectrumValue[1], 0, 0);
strip.setPixelColor(6, spectrumValue[0], 0, 0);
strip.setBrightness(global_brightness);
strip.show();
}
void nextLed(int r, int g, int b, int wait){
static int currentLed = 0;
strip.setPixelColor(currentLed, r, g, b);
delay(wait);
//if (currentLed % 4 == 0)
// strip.show();
currentLed++;
if (currentLed >= strip.numPixels() ){
currentLed = 0;
strip.show();
}
}
// List of patterns to cycle through. Each is defined as a separate function below.
typedef void (*SimplePatternList[])();
SimplePatternList gPatterns = {SineDemo, pattern3, ripple, ripple2, sinelon, fire, fireblu, FirePurp};
uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current
void nextPattern()
{
// add one to the current pattern number, and wrap around at the end
gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns);
}
void All()
{
// Call the current pattern function once, updating the 'leds' array
gPatterns[gCurrentPatternNumber]();
EVERY_N_SECONDS( 30 ) { nextPattern(); } // change patterns periodically
}
credo che possa risparmiare qualcosa modificando questo"
- Codice: Seleziona tutto
int buttonVal = digitalRead(12);
if (buttonVal == LOW && oldButtonVal == HIGH) {// button has just been pressed
lightPattern = lightPattern + 1;
}
if (lightPattern > nPatterns) lightPattern = 1;
oldButtonVal = buttonVal;
switch(lightPattern) {
per il momento vi ringrazio
e vi auguro buone feste

Elettrotecnica e non solo (admin)
Un gatto tra gli elettroni (IsidoroKZ)
Esperienza e simulazioni (g.schgor)
Moleskine di un idraulico (RenzoDF)
Il Blog di ElectroYou (webmaster)
Idee microcontrollate (TardoFreak)
PICcoli grandi PICMicro (Paolino)
Il blog elettrico di carloc (carloc)
DirtEYblooog (dirtydeeds)
Di tutto... un po' (jordan20)
AK47 (lillo)
Esperienze elettroniche (marco438)
Telecomunicazioni musicali (clavicordo)
Automazione ed Elettronica (gustavo)
Direttive per la sicurezza (ErnestoCappelletti)
EYnfo dall'Alaska (mir)
Apriamo il quadro! (attilio)
H7-25 (asdf)
Passione Elettrica (massimob)
Elettroni a spasso (guidob)
Bloguerra (guerra)






