tonemelody

hi
i have a nrf24l01 and i want when the swich is high a melody play but h dont know how to mach these two codes .

nrf24lo1

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
int msg[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int LED1 = 3;
#include "pitches.h"

void setup(void){
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();
pinMode(LED1, OUTPUT);}

void loop(void){
if (radio.available()){
bool done = false;
while (!done){
done = radio.read(msg, 1);
Serial.println(msg[0]);
if (msg[0] == 111){delay(10);digitalWrite(LED1, HIGH);}
else {digitalWrite(LED1, LOW);}
delay(10);}}
else{Serial.println("No radio available");}}

tonemelody

 */
#include "pitches.h"

// notes in the melody:
int melody[] = {
  NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4
};

// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
  4, 8, 8, 4, 4, 4, 4, 4
};

void setup() {
  // iterate over the notes of the melody:
  for (int thisNote = 0; thisNote < 8; thisNote++) {

    // to calculate the note duration, take one second
    // divided by the note type.
    //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
    int noteDuration = 1000 / noteDurations[thisNote];
    tone(8, melody[thisNote], noteDuration);

    // to distinguish the notes, set a minimum time between them.
    // the note's duration + 30% seems to work well:
    int pauseBetweenNotes = noteDuration * 1.30;
    delay(pauseBetweenNotes);
    // stop the tone playing:
    noTone(8);
  }
}

void loop() {
  // no need to repeat the melody.
}

please help …

Hi, How many nRF24L01 units do you have?

I assume you want to play a melody when the nRF24L01 receives a signal.

What transmits the signal and what command do you want to send?

Tom... :)

when switch is high i want the melody play and when the switch is low the melody dont play .....

no one cant help me ???????

What switch? How does the radio figure into your plans?

Can you draw a schematic? Please not F***zing. A pencil sketch photographed with a phone is okay.

If you want to merge two sketches, combine their setup() code into the setup() function of the new sketch, and their loop() code into the new loop().

But the result will not do what you expect, as long as the code is blocking, i.e. using delay().

If you cannot rewrite the code without delay(), according to the method outlined in "several things at the same time", you can use the task macros to make the loops non-blocking. For that purpose rename the two loop() functions into e.g. loop1() and loop2(), and add beginTask(); and endTask(); to the new functions, and replace every delay() by taskDelay(). Finally call all tasks in the new loop() function, i.e.

void loop() {
 loop1();
 loop2();
}