Wiki Info
Vuoi reagire a questo messaggio? Crea un account in pochi click o accedi per continuare.
Ricerca Avanzata
Answers
Se necessiti di aiuto, clicca il pulsante "Cerco Aiuto" (disponibile anche per i non iscritti).
Ultimi argomenti attivi
» Comunicazione termine servizio Arduino BT Control
Da Admin Mar Mag 10, 2022 12:55 pm

» Robot aspirapolvere per Alexa: Dreame D9
Da Admin Mar Feb 09, 2021 9:42 am

» Come costruire un robot smart con Arduino
Da Admin Mar Nov 17, 2020 12:15 pm

» TOPPS Trading Cards Match Attax Champsion League/Europa League 2020/21
Da Admin Mar Nov 10, 2020 3:21 pm

» Guida per utilizzare Arduino BT Control v1.2
Da Admin Gio Lug 09, 2020 12:01 pm

» Recensione Umidigi A3 Pro - Smartphone sotto i 100€
Da Admin Gio Apr 04, 2019 12:22 pm

» [Arduino] aiuto programma
Da Glak Mar Mar 12, 2019 9:30 am

» ERRORE NELLA COMPILAZIONE NEXTION
Da papat Mar Feb 26, 2019 7:11 am

» Comandare la Smart TV con Alexa senza broadlink (gratis)
Da Admin Mar Feb 19, 2019 4:31 pm

I postatori più attivi del mese
Nessun utente


sketch non valido

2 partecipanti

Andare in basso

include - sketch non valido Empty sketch non valido

Messaggio Da fulvio calvarano Gio Gen 03, 2019 4:25 pm

#include "pitches.h"

const int piezoPin = 12; //piezo
const int rPin = 5;  //red LED
const int gPin = 4;  //green LED
const int bPin = 3;  //blue LED
const int pPin = 2;  //pushbutton

int ledState = 0;
int ledOn = false;

// notes
int melody[] = {
 NOTE_F5,NOTE_D5,NOTE_AS4,NOTE_D5,NOTE_F5,NOTE_AS5,NOTE_D6,NOTE_C6,NOTE_AS5,NOTE_D5,NOTE_E5,NOTE_F5,
 NOTE_F5,NOTE_F5,NOTE_D6,NOTE_C6,NOTE_AS5,NOTE_A5,NOTE_G5,NOTE_A5,NOTE_AS5,NOTE_AS5,NOTE_F5,NOTE_D5,NOTE_AS4,
 NOTE_D6,NOTE_D6,NOTE_D6,NOTE_DS6,NOTE_F6,NOTE_F6,NOTE_DS6,NOTE_D6,NOTE_C6,NOTE_D6,NOTE_DS6,NOTE_DS6,
 0,NOTE_DS6,NOTE_D6,NOTE_C6,NOTE_AS5,NOTE_A5,NOTE_G5,NOTE_A5,NOTE_AS5,NOTE_D5,NOTE_E5,NOTE_F5,
 NOTE_F5,NOTE_AS5,NOTE_AS5,NOTE_AS5,NOTE_A5,NOTE_G5,NOTE_G5,NOTE_G5,NOTE_C6,NOTE_DS6,NOTE_D6,NOTE_C6,NOTE_AS5,NOTE_AS5,NOTE_A5,
 NOTE_F5,NOTE_F5,NOTE_AS5,NOTE_C6,NOTE_D6,NOTE_DS6,NOTE_F6,NOTE_AS5,NOTE_C6,NOTE_D6,NOTE_DS6,NOTE_C6,NOTE_AS5
};

// durations: 2 = half note, and 8/3,4,6,8,12. It appears that 8/2.9 is more accurate than 8/3.
float noteDurations[] = {
 6,12,4,4,4,2,6,12,4,4,4,2,
 8,8,8/2.9,8,4,2,8,8,4,4,4,4,4,
 6,12,4,4,4,2,8,8,4,4,4,2,
 8,8,8/2.9,8,4,2,8,8,4,4,4,2,
 4,4,4,8,8,4,4,4,4,8,8,8,8,4,4,
 8,8,8/2.9,8,8,8,2,8,8,4,4,4,2
};

// calculates the number of elements in the melody array.
int musicLength=sizeof(melody)/sizeof('NOTE_F5');

void setup() {  
 pinMode(pPin, INPUT);
 pinMode(rPin, OUTPUT);
 pinMode(gPin, OUTPUT);
 pinMode(bPin, OUTPUT);
}

void loop() {
 int pPinState=digitalRead(pPin);
 if(pPinState==HIGH) {
   ledState = 1;
 }
 if (pPinState==LOW and ledState ==1) {
   ledState = 2;
   ledOn = not ledOn;
 }
 if (ledOn && pPinState!=HIGH) {
   for (int thisNote = 0; thisNote < musicLength; thisNote++) {
     // blink the three LEDs in sequence
     if (thisNote%3==0){    
       digitalWrite(rPin, HIGH);
       digitalWrite(gPin, LOW);
       digitalWrite(bPin, LOW);
     }
     else if (thisNote%3==1){    
       digitalWrite(rPin, LOW);
       digitalWrite(gPin, HIGH);
       digitalWrite(bPin, LOW);
     }
     else if (thisNote%3==2){    
       digitalWrite(rPin, LOW);
       digitalWrite(gPin, LOW);
       digitalWrite(bPin, HIGH);
     }

     // calculate the note duration. change tempo by changing 2000 to other values
     int noteDuration = 2000/noteDurations[thisNote];
     tone(piezoPin, melody[thisNote],noteDuration);
     
     // to distinguish the notes, set a minimum time between them.
     // the note's duration + 30% seems to work well
     float pauseBetweenNotes = noteDuration * 1.30;
     
     //split the delay into two parts and check to see
     //whether the pushbutton is pressed to turn off
     //the sound and light
     delay(pauseBetweenNotes/2);
     if(digitalRead(pPin)==HIGH) {
       break;      
     }
     delay(pauseBetweenNotes/2);
     if(digitalRead(pPin)==HIGH) {
       break;      
     }
   }
 }
 else if (not ledOn) {
   digitalWrite(rPin, LOW);
   digitalWrite(gPin, LOW);
   digitalWrite(bPin, LOW);
 }
}
Intanto mi scuso se le modalità di invio non son quelle  giuste per il forum....Da un paio di anni ho abbandonato i progetti di Arduino,progetti  che ho sempre copiato.Uno di essi era riprodurre con l
led e suoni l'inno USA.Oggi ho ripreso a giocarci ma lo sketch che avevo salvato non funziona.La verifica mi dà questo messaggio:  pitches.h no such file or directory. 

Invio lo sketch che funzionava bene
Grazie per l'aiuto ed eventuali consigli 


#include "pitches.h"

const int piezoPin = 12; //piezo
const int rPin = 5;  //red LED
const int gPin = 4;  //green LED
const int bPin = 3;  //blue LED
const int pPin = 2;  //pushbutton

int ledState = 0;
int ledOn = false;

// notes
int melody[] = {
 NOTE_F5,NOTE_D5,NOTE_AS4,NOTE_D5,NOTE_F5,NOTE_AS5,NOTE_D6,NOTE_C6,NOTE_AS5,NOTE_D5,NOTE_E5,NOTE_F5,
 NOTE_F5,NOTE_F5,NOTE_D6,NOTE_C6,NOTE_AS5,NOTE_A5,NOTE_G5,NOTE_A5,NOTE_AS5,NOTE_AS5,NOTE_F5,NOTE_D5,NOTE_AS4,
 NOTE_D6,NOTE_D6,NOTE_D6,NOTE_DS6,NOTE_F6,NOTE_F6,NOTE_DS6,NOTE_D6,NOTE_C6,NOTE_D6,NOTE_DS6,NOTE_DS6,
 0,NOTE_DS6,NOTE_D6,NOTE_C6,NOTE_AS5,NOTE_A5,NOTE_G5,NOTE_A5,NOTE_AS5,NOTE_D5,NOTE_E5,NOTE_F5,
 NOTE_F5,NOTE_AS5,NOTE_AS5,NOTE_AS5,NOTE_A5,NOTE_G5,NOTE_G5,NOTE_G5,NOTE_C6,NOTE_DS6,NOTE_D6,NOTE_C6,NOTE_AS5,NOTE_AS5,NOTE_A5,
 NOTE_F5,NOTE_F5,NOTE_AS5,NOTE_C6,NOTE_D6,NOTE_DS6,NOTE_F6,NOTE_AS5,NOTE_C6,NOTE_D6,NOTE_DS6,NOTE_C6,NOTE_AS5
};

// durations: 2 = half note, and 8/3,4,6,8,12. It appears that 8/2.9 is more accurate than 8/3.
float noteDurations[] = {
 6,12,4,4,4,2,6,12,4,4,4,2,
 8,8,8/2.9,8,4,2,8,8,4,4,4,4,4,
 6,12,4,4,4,2,8,8,4,4,4,2,
 8,8,8/2.9,8,4,2,8,8,4,4,4,2,
 4,4,4,8,8,4,4,4,4,8,8,8,8,4,4,
 8,8,8/2.9,8,8,8,2,8,8,4,4,4,2
};

// calculates the number of elements in the melody array.
int musicLength=sizeof(melody)/sizeof('NOTE_F5');

void setup() {  
 pinMode(pPin, INPUT);
 pinMode(rPin, OUTPUT);
 pinMode(gPin, OUTPUT);
 pinMode(bPin, OUTPUT);
}

void loop() {
 int pPinState=digitalRead(pPin);
 if(pPinState==HIGH) {
   ledState = 1;
 }
 if (pPinState==LOW and ledState ==1) {
   ledState = 2;
   ledOn = not ledOn;
 }
 if (ledOn && pPinState!=HIGH) {
   for (int thisNote = 0; thisNote < musicLength; thisNote++) {
     // blink the three LEDs in sequence
     if (thisNote%3==0){    
       digitalWrite(rPin, HIGH);
       digitalWrite(gPin, LOW);
       digitalWrite(bPin, LOW);
     }
     else if (thisNote%3==1){    
       digitalWrite(rPin, LOW);
       digitalWrite(gPin, HIGH);
       digitalWrite(bPin, LOW);
     }
     else if (thisNote%3==2){    
       digitalWrite(rPin, LOW);
       digitalWrite(gPin, LOW);
       digitalWrite(bPin, HIGH);
     }

     // calculate the note duration. change tempo by changing 2000 to other values
     int noteDuration = 2000/noteDurations[thisNote];
     tone(piezoPin, melody[thisNote],noteDuration);
     
     // to distinguish the notes, set a minimum time between them.
     // the note's duration + 30% seems to work well
     float pauseBetweenNotes = noteDuration * 1.30;
     
     //split the delay into two parts and check to see
     //whether the pushbutton is pressed to turn off
     //the sound and light
     delay(pauseBetweenNotes/2);
     if(digitalRead(pPin)==HIGH) {
       break;      
     }
     delay(pauseBetweenNotes/2);
     if(digitalRead(pPin)==HIGH) {
       break;      
     }
   }
 }
 else if (not ledOn) {
   digitalWrite(rPin, LOW);
   digitalWrite(gPin, LOW);
   digitalWrite(bPin, LOW);
 }
}
fulvio calvarano
fulvio calvarano
Livello uno
Livello uno

Messaggi Messaggi : 15
Crediti Crediti : 29
Reputazione Reputazione : 0
Data d'iscrizione Data d'iscrizione : 03.01.19
Età Età : 75
Località Località : Trieste

Torna in alto Andare in basso

include - sketch non valido Empty Re: sketch non valido

Messaggio Da Admin Ven Gen 18, 2019 5:15 pm

ciao assicurati che le libreria siano importate
Admin
Admin
♔ Amministratore

Messaggi Messaggi : 4370
Crediti Crediti : 12173
Reputazione Reputazione : 187
Data d'iscrizione Data d'iscrizione : 08.03.11
Età Età : 25

https://wikiinfo.forumattivo.it

Torna in alto Andare in basso

include - sketch non valido Empty Re: sketch non valido

Messaggio Da fulvio calvarano Mar Gen 22, 2019 7:08 am

Grazie.Scusa il ritardo;ero all'estero.
Risolto
fulvio calvarano
fulvio calvarano
Livello uno
Livello uno

Messaggi Messaggi : 15
Crediti Crediti : 29
Reputazione Reputazione : 0
Data d'iscrizione Data d'iscrizione : 03.01.19
Età Età : 75
Località Località : Trieste

Torna in alto Andare in basso

include - sketch non valido Empty Re: sketch non valido

Messaggio Da Contenuto sponsorizzato


Contenuto sponsorizzato


Torna in alto Andare in basso

Torna in alto

- Argomenti simili

 
Permessi in questa sezione del forum:
Non puoi rispondere agli argomenti in questo forum.