..Comments about memory space and large amounts of static data in the sketch have merit. Consider moving your static (unchanging) data from limited RAM to FLASH memory. This resource explains how this is accomplished.
I'm trying to make an OO state machine based program to play music and lights at the same time. It uses the FastLED library and a 13 pixel neopixel strip. I've confirmed that with the currently wired setup that I can separately play music and also separately run the FastLED Cylon example code. However when I upload the code below it just kinda hangs out and doesn't do anything and doesn't even print the statements in the setup statement. The weird thing is that if I comment out the Lights lightstrip1() instantiation line and the lightstrip.Update() line, it does play the melody part ok.
#include "pitches.h"
#include "FastLED.h"
class Melody
/ notes in the melody Minuet in G.
int melody NOTE_D4, NOTE_G3, NOTE_A3, NOTE_B3, NOTE_C4, NOTE_D4, NOTE_G3, NOTE_G3, NOTE_E4, NOTE_C4, NOTE_D4, NOTE_E4, NOTE_FS4, NOTE_G4, NOTE_G3, NOTE_G3, NOTE_C4, NOTE_D4, NOTE_C4, NOTE_B3, NOTE_A3, NOTE_B3, NOTE_C4, NOTE_B3, NOTE_A3, NOTE_G3, NOTE_FS3,NOTE_G3, NOTE_A3, NOTE_B3, NOTE_G3, NOTE_A3, NOTE_D4, NOTE_G3, NOTE_A3, NOTE_B3, NOTE_C4, NOTE_D4, NOTE_G3, NOTE_G3, NOTE_E4, NOTE_C4, NOTE_D4, NOTE_E4, NOTE_FS4, NOTE_G4, NOTE_G3, NOTE_G3, NOTE_C4, NOTE_D4, NOTE_C4, NOTE_B3, NOTE_A3, NOTE_B3, NOTE_C4, NOTE_B3, NOTE_A3, NOTE_G3, NOTE_A3, NOTE_B3, NOTE_A3, NOTE_G3, NOTE_FS3, NOTE_G3, / Second part NOTE_B4, NOTE_G4, NOTE_A4, NOTE_B4, NOTE_G4, NOTE_A4, NOTE_D4, NOTE_E4, NOTE_FS4, NOTE_D4, NOTE_G4, NOTE_E4, NOTE_FS4, NOTE_G4, NOTE_D4, NOTE_CS4, NOTE_B3, NOTE_CS4, NOTE_A3, NOTE_A3, NOTE_B3, NOTE_CS4, NOTE_D4, NOTE_E4, NOTE_FS4, NOTE_G4, NOTE_FS4, NOTE_E4, NOTE_FS4, NOTE_A3, NOTE_CS4, NOTE_D4, / BACK TO G MAJOR!!!! NOTE_D4, NOTE_G3, NOTE_FS3, NOTE_G3, NOTE_E4, NOTE_G3, NOTE_FS3, NOTE_G3, NOTE_D4, NOTE_C4, NOTE_B3, NOTE_A3, NOTE_G3, NOTE_FS3, NOTE_G3, NOTE_A3, NOTE_D3, NOTE_E3, NOTE_FS3, NOTE_G3, NOTE_A3, NOTE_B3, NOTE_C4, NOTE_B3, NOTE_A3, NOTE_B3, NOTE_D4, NOTE_G3, NOTE_FS3, NOTE_G3 ;
/ note durations: 4 quarter note, 8 eighth note, etc.:
float noteDurations 4, 8,8,8,8, 4, 4, 4, 4, 8,8,8,8, 4, 4, 4, 4, 8,8,8,8, 4, 8,8,8,8, 4, 8,8,8,8, 1.5, 4, 8,8,8,8, 4, 4, 4, 4, 8,8,8,8, 4, 4, 4, 4, 8,8,8,8, 4, 8,8,8,8, 4, 8,8,8,8, 1.5, / Second part 4, 8,8,8,8, 4, 8,8,8,8, 4, 8,8,8,8, 4, 8,8, 4, 8,8,8,8,8,8, 4, 4, 4, 4, 4, 4, 1.5, 4, 8,8, 4, 4, 8,8, 4, 4, 4, 4, 8,8,8,8, 4, 8,8,8,8,8,8, 4,4,4, 8,8,4,4, 1.5 ; unsigned long OnTime; / This will be the time in millis to turn on a note. unsigned long OffTime; / This will be the time in millis to turn off a note. int ToneState; unsigned long previousMillis; int speakerPin; int noteNumber; int maxNoteNumber; public: Melody(int pin) speakerPin pin; pinMode(speakerPin, OUTPUT); previousMillis 0; OnTime previousMillis; ToneState 0; / Off noteNumber 0; / Start at the first note.
/ maxNoteNumber sizeof(noteDurations); / This turns out to 504 for some reason. maxNoteNumber 125; void Update() unsigned long currentMillis millis(); if (ToneState 0 && currentMillis > OnTime) tone(speakerPin, melody[noteNumber]); OffTime currentMillis (1000 / noteDurations[noteNumber]); ToneState 1; Serial.print(noteNumber); Serial.print(""); Serial.println(maxNoteNumber); else if (ToneState 1 && currentMillis > OffTime) noTone(speakerPin); OnTime currentMillis ((1000 / noteDurations[noteNumber]) * 0.30); ToneState 0; if (noteNumber (leds, ledCount); / It complains if I try to use a variable for the 7. It has to be a constant. for (int i 0; i NextOn) if (ledOn > ledCount) leds[ledOn] CRGB::Black; ledOn 0; leds[ledOn] CRGB::Red; else if (ledOn 0) leds[ledCount - CRGB::Black; leds[ledOn] CRGB::Red; / Need to put RGB to HSV converter in later. else leds[ledOn - CRGB::Black; leds[ledOn] CRGB::Red; / Need to put RGB to HSV converter in later. Serial.print("LED: "); Serial.println(ledOn); Serial.println(NextOn); FastLED.show(); NextOn currentMillis2 lightdelay; ledOn;
;
Melody melody1(2);
Lights lightstrip1(7, 12, 250, 0, 0);
void setup() Serial.begin(115200); Serial.println("Started");
void loop() melody1.Update(); lightstrip1.Update();
Any ideas?
Copyright © 2020 Shandong Abusair Agricultural Machinery Co,. Ltd- | Sitemap
Multifunctional farm Abusair machinery | Tea Professional Cultivator farm machinery
{"site":{"site_id":1404,"site_type":1,"site_domain":"lederformwork.com","domain_mode":1,"original_domain":"lederformwork.com","language_code":"it","is_init_domain":0,"is_shop":false,"is_ssl":1,"lang_prefix":"/","animate_name":"none"},"page":{"page_id":54199,"page_type":"ai_article_detail","page_code":423,"page_url":"/ai-article/can-t-play-melody-and-fastled-lights-at-same-time.html","page_source":"","allowAnimat":0,"content_id":5168,"content_type":5,"detail_thumb":"","detail_title":"Can't Play Melody and FastLED Lights at Same Time","moq":1},"translateList":{"A new item has been added to your Shopping Cart":"Un nuovo oggetto è stato aggiunto al tuo carrello","Account is not exists":"L'account non è esista","Add a review on the product":"Aggiungi una recensione sul prodotto","Add to":"Aggiungere a","Add to Cart":"Aggiungi al carrello","all":"tutti","All Orders":"Tutti gli ordini","Already commented":"Già commentato","Are you sure you want to delete it?":"Sei sicuro di voler cancellare?","Are you sure to delete the selected items?":"Sei sicuro di eliminare gli elementi selezionati?","Awaiting Payment":"In attesa del pagamento","Awaiting Shipment":"In attesa della spedizione","account security":"Sicurezza dell 'Account","address book":"rubrica","Buy":"Acquistare","Buy Now":"acquista ora","Cancel":"Annulla","Clear":"Chiaro","Clear Search":"Cancella ricerca.","Confirm":"Confermare","Choose a country":"Scegli un paese","Choose Coupon":"Scegli il coupon.","commodity payment":"pagamento delle materie prime","Completed":"completato","Condition not met":"Condizione non soddisfatta","Confirm password is inconsistent with new password":"Conferma la password è incoerente con la nuova password","Congratulations":"Congratulazioni","Congratulations! You are got a coupon.":"Congratulazioni! Hai un coupon.","Congratulations! You are got all coupons.":"Congratulazioni! Hai tutti i coupon.","Continue Shopping":"continua a fare acquisti","Copy the code and use it directly in the shopping cart.":"Copia il codice e usalo direttamente nel carrello della spesa.","Coupon List":"Elenco dei coupon","Country":"nazione","Design customization":"Personalizzazione del design.","Do not use any discount":"Non usare alcun sconto","Earliest":"Più presto","email":"e-mail","email format does not match":"Il formato e-mail non corrisponde","Estimated Delivery Time":"Tempi di consegna stimati","expired":"scaduto","Find Parts":"Trova parti","Free":"Libero","Free Quote & Information Request":"Citazione gratuita e richiesta di informazioni","Free Shipping":"Spedizione gratuita","for order over":"per ordine oltre","Get":"Ottenere","Get coupons":"Ottieni coupon","Get discount":"Scontata","Get it":"Prendilo","Get it after logging in and use it in the shopping cart.":"Prendilo dopo averlo accesso e usalo nel carrello della spesa.","Go to Page":"Vai alla pagina","Highest Price":"Il prezzo più alto","Hot Sale":"Vendita calda","home":"casa","Incorrect form format":"Formato modulo errato","inquiry":"inchiesta","Loading":"Caricamento in corso","Lowest Price":"Prezzo più basso","Match Product":"Abbinare il prodotto","Merchant Free Shipping":"Merchant Spedizione gratuita.","Most Popular":"Più popolare","my account":"il mio conto","my coupons":"i miei coupon","my inquiry":"la mia richiesta","my orders":"i miei ordini","my reviews":"Le mie recensioni","my wishlist":"La mia lista dei desideri","name":"nome","Newest":"Più recente","No Quotation":"Nessuna quotazione","No time limit":"Nessun limite di tempo","Not deleted":"Non cancellato","not valid yet":"non è ancora valido","Off":"Spento","Offers and Discounts":"Offerte e sconti","ok":"ok","optional":"opzionale","Order over":"Ordine oltre","order notes":"Note d'ordine","Password contains at least numbers and letters length should be 6-20":"La password contiene almeno numeri e lettere lettere dovrebbero essere 6-20","Password is invalid":"La password non è valida","Password length should be 6-20":"La lunghezza della password dovrebbe essere 6-20","Paypal":"Paypal","paypal payment":"Pagamento PayPal.","personal info":"informazioni personali","Please click ’click to continue’ to retry.":"Fai clic su \"Clicca per continuare\" per riprovare.","Please enter a valid email address":"Si prega di inserire un indirizzo email valido","Please enter the verification code":"Si prega di inserire il codice di verifica","Please login in first":"Per favore accedi prima","Please select attribute":"Si prega di selezionare Attributo.","Please select country/region":"Si prega di selezionare Paese / Regione","Please select superior":"Si prega di selezionare Superior","Please select the number of ratings.":"Si prega di selezionare il numero di valutazioni.","read more":"Per saperne di più","Region":"Regione","Register Success":"Registrare il successo","Sale ends in":"Vendita termina in.","Save in wishlist":"Salva nella wishlist.","Search":"Ricerca","Shipping":"spedizione","Shipping Address":"indirizzo di spedizione","shipment successful":"Spedizione riuscita","Size guide":"Guida alle taglie","Small Text":"Piccolo testo","Small Title":"Piccolo titolo","Sort By":"Ordina per","State/Province/Territory":"Stato / Provincia / Territorio","Successfully delete":"Elimina con successo","Successfully save":"Risparmi con successo","The coupon code has been copied and used in the shopping cart.":"Il codice coupon è stato copiato e utilizzato nel carrello della spesa.","The subscription is successful, thank you for your participation":"L'abbonamento ha successo, grazie per la tua partecipazione","The user center is out of service. Please contact customer service":"L'utente è fuori servizio. Si prega di contattare il servizio clienti","This is Text":"Questo è testo.","This is title":"Questo è il titolo","This transaction has failed.":"Questa transazione ha fallito.","Time to shop":"Tempo per fare acquisti","To be commented":"Essere commentato","Total":"Totale","the content can not be blank":"Il contenuto non può essere vuoto","Update password success":"Aggiorna il successo della password","Upload Image":"Carica immagine","Upload up to 6 pictures":"Carica fino a 6 immagini","uploading":"Carica","used":"Usato","user center":"Centro utente","Validity period":"Periodo di validità","valid now":"Valido ora","View Cart & Checkout":"Visualizza il carrello","Welcome to the website":"Benvenuto nel sito web","Western Union":"Western Union","Write a Review":"Scrivere una recensione","You are got a coupon.":"Hai un coupon.","You haven’t chosen an address yet":"Non hai ancora scelto un indirizzo","You haven’t selected a product yet":"Non hai ancora selezionato un prodotto","Your rating":"Il tuo punteggio","Your review":"Il tuo commento","Your shipping address error":"Il tuo errore dell'indirizzo di spedizione"}}