#include "PCM.h"
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define led1 A0
int buttonState = 0;
bool samplePlayed = false; // Flag to track if the sample has been played
RF24 radio(9, 8); // CE, CSN
const byte address[6] = "00002";
const byte sample[] PROGMEM = {
107, 148, 97, 162, 104, 102, 153, 174, 90, 37, 216, 55, 146, 244, 146, 109, 81, 93, 74, 53, 130, 137, 130, 246, 225, 155, 172, 107, 93, 79, 0, 65, 65, 109, 160, 153, 246, 202, 197, 186, 81, 134, 44, 6, 90, 27, 95, 174, 165, 230, 202, 209, 223, 107, 118, 48, 0, 79, 55, 93, 183, 165, 235, 249, 190, 223, 125, 69, 88, 2, 18, 32, 37, 186, 225, 230, 242, 193, 228, 162, 74, 76, 0, 13, 65, 69, 134, 169, 218, 255, 228, 204, 169, 118, 74, 27, 13, 39, 65, 104, 162, 207, 242, 235, 218, 195, 137, 93, 30, 9, 23, 46, 102, 146, 200, 251, 244, 235, 202, 151, 97, 30, 2, 13, 37, 100, 160, 183, 232, 255, 230, 209, 151, 93, 51, 9, 2, 32, 95, 155, 195, 223, 239, 228, 195, 160, 104, 53, 23, 13, 44, 83, 134, 181, 207, 225, 230, 207, 162, 121, 69, 44, 41, 27, 58, 111, 160, 207, 221, 225, 218, 186, 148, 88, 39, 23, 20, 55, 107, 144, 186, 223, 242, 237, 195, 146, 93, 41, 20, 16, 44, 93, 141, 193, 230, 244, 225, 197, 158, 100, 41, 6, 18, 51, 102, 146, 181, 218, 232, 223, 190, 151, 104, 60, 32, 18, 48, 93, 139, 186, 202, 218, 221, 190, 158, 116, 72, 46, 32, 46, 83, 121, 162, 190, 216, 228, 197, 167, 137, 86, 55, 27, 30, 76, 114, 151, 188, 211, 230, 218, 181, 139, 88, 51, 32, 30, 65, 97, 144, 195, 218, 230, 218, 176, 148, 100, 46, 27, 25, 65, 109, 146, 183, 209, 225, 216, 181, 148, 95, 55, 41, 34, 67, 109, 139, 179, 204, 209, 204, 172, 146, 111, 74, 53, 39, 67, 102, 128, 167, 190, 202, 207, 181, 151, 128, 88, 60, 51, 55, 90, 118, 148, 181, 202, 211, 195, 165, 134, 97, 65, 46, 48, 76, 107, 144, 179, 207, 216, 195, 172, 141, 97, 67, 44, 41, 79, 107, 141, 181, 195, 209, 197, 172, 146, 100, 65, 53, 55, 81, 109, 132, 167, 190, 200, 190, 165, 144, 114, 83, 67, 58, 76, 109, 132, 160, 179, 186, 181, 165, 153, 123, 95, 79, 69, 81, 102, 121, 148, 172, 186, 183, 169, 153, 128, 104, 81, 65, 76, 95, 121, 148, 169, 188, 188, 172, 153, 130, 97, 79, 69, 74, 97, 116, 148, 172, 181, 186, 169, 153, 132, 97, 81, 67, 76, 102, 121, 148, 165, 181, 183, 167, 151, 125, 102, 88, 74, 81, 97, 121, 144, 162, 172, 172, 165, 148, 137, 111, 93, 86, 83, 97, 116, 130, 153, 165, 174, 169, 153, 141, 121, 100, 88, 81, 88, 109, 125, 151, 165, 174, 172, 160, 144, 123, 102, 86, 79, 86, 109, 125, 146, 167, 174, 172, 160, 144, 123, 100, 83, 79, 90, 109, 128, 146, 160, 172, 169, 158, 144, 123, 102, 90, 83, 90, 107, 125, 144, 158, 165, 165, 155, 141, 130, 111, 100, 93, 95, 109, 121, 137, 148, 155, 160, 155, 144, 134, 118, 104, 97, 95, 104, 116, 132, 146, 155, 162, 158, 148, 137, 118, 104, 95, 90, 102, 114, 130, 146, 158, 165, 160, 151, 134, 121, 104, 93, 93, 97, 114, 132, 144, 158, 165, 160, 148, 134, 121, 107, 97, 93, 104, 116, 128, 144, 151, 158, 155, 146, 137, 125, 111, 102, 97, 104, 116, 125, 137, 148, 151, 153, 146, 137, 130, 116, 107, 104, 102, 111, 123, 132, 144, 151, 153, 151, 139, 132, 123, 107, 102, 102, 107, 118, 130, 141, 151, 153, 151, 144, 132, 121, 109, 102, 102, 107, 118, 132, 141, 151, 151, 148, 141, 132, 121, 107, 104, 102, 111, 123, 130, 141, 148, 148, 146, 139, 130, 121, 111, 107, 107, 111, 123, 130, 137, 144, 144, 144, 139, 132, 125, 116, 109, 109, 114, 118, 125, 134, 141, 146, 146, 141, 134, 128, 121, 111, 107, 109, 114, 123, 132, 141, 146, 148, 144, 139, 130, 118, 111, 107, 104, 114, 123, 132, 141, 148, 148, 146, 137, 128, 118, 109, 107, 107, 114, 123, 132, 141, 144, 146, 144, 134, 128, 118, 109, 109, 109, 116, 125, 132, 139, 144, 141, 139, 134, 128, 121, 114, 111, 114, 118, 125, 130, 134, 141, 141, 139, 134, 128, 125, 116, 111, 114, 116, 123, 128, 134, 139, 141, 139, 134, 130, 125, 118, 114, 114, 116, 123, 128, 134, 139, 141, 139, 134, 130, 123, 118, 114, 114, 118, 123, 130, 134, 139, 139, 137, 134, 128, 123, 118, 114, 116, 118, 123, 130, 132, 134, 137, 134, 132, 128, 123, 121, 118, 118, 121, 123, 128, 130, 132, 134, 132, 132, 130, 125, 123, 121, 121, 121, 123, 128, 130, 132, 132, 134, 132, 130, 128, 123, 121, 121, 121, 123, 125, 130, 132, 132, 134, 132, 130, 128, 123, 121, 118, 118, 123, 125, 130, 130, 132, 134, 132, 130, 128, 123, 121, 121, 121, 123, 125, 128, 132, 132, 132, 132, 130, 128, 125, 123, 121, 123, 123, 125, 128, 130, 130, 130, 130, 128, 125, 125, 123, 123, 123, 125, 125, 128, 130, 130, 130, 130, 128, 128, 125, 125, 123, 123, 123, 125, 128, 130, 130, 130, 130, 130, 128, 125, 125, 123, 123, 123, 125, 128, 128, 130, 130, 130, 130, 128, 125, 123, 123, 123, 123, 125, 128, 128, 130, 130, 130, 128, 128, 125, 125, 123, 123, 123, 125, 128, 128, 130, 130, 130, 128, 128, 125, 125, 125, 123, 125, 125, 128, 128, 128, 128, 128, 128, 128, 125, 125, 125, 125, 125, 125, 128, 128, 128, 128, 128, 128, 128, 128, 125, 125, 125, 125, 125, 128, 128, 128, 128, 128, 128, 128, 125, 125, 125, 125, 125, 125, 128, 128, 128, 128, 128, 128, 128, 125, 125, 125, 125, 125, 125, 128, 128, 128, 128, 128, 128, 128, 125, 125, 125, 125, 125, 125, 128, 128, 128, 128, 128, 128, 128, 125, 125, 125, 125, 125, 125, 128, 128, 128, 128, 128, 128, 128, 125, 125, 125, 125, 125, 125, 125, 128, 128, 128, 128, 128, 128, 128, 125, 125, 125, 125, 125, 125, 128, 128, 128, 128, 128, 128, 125, 125, 125, 125, 125, 125, 125, 128, 128, 128, 128, 128, 128, 125, 125, 125, 125, 125, 125, 125, 128, 128, 128, 128, 128, 128, 125, 125, 125, 125, 125, 125, 128, 128, 128, 128, 128, 128, 128, 128, 125, 125, 125, 125, 125, 125, 128, 128, 128, 128, 128, 128, 128, 125, 125, 125, 125, 125, 125, 128, 128, 128, 128, 128, 128, 128, 125, 125, 125, 125, 125, 125, 128, 128, 128, 128, 128, 128, 128, 125, 125, 125, 125, 125, 125, 128, 128, 128, 128, 128, 128, 128, 125, 125, 125, 125, 125, 125, 128, 128, 128, 128, 128, 128, 128, 125, 125, 125, 125, 125, 125, 125, 128, 128, 128, 128, 128, 128, 125, 125, 125, 125, 125, 125, 128, 128, 128, 128, 128, 128, 128, 128, 125, 125, 125, 125, 125, 125, 128, 128, 128, 128, 128, 128, 125, 125, 125, 125, 125, 125, 128, 128, 128, 128, 128, 128, 128, 125, 125, 125, 125, 125, 125, 128, 128, 128, 128, 128, 128, 128, 125, 125, 125, 125, 125, 125, 125, 128, 128, 128, 128, 128, 128, 128, 125, 125, 125, 125, 125, 125, 125, 128, 128, 128, 128, 128, 128, 125, 125, 125, 125, 125, 125, 128, 128, 128, 128, 128, 128, 128, 125, 125, 125, 125, 125, 125, 128, 128, 128, 128, 128, 128, 128, 125, 125, 125, 125, 125, 125, 128, 128, 128, 128, 128,
};
void setup() {
pcm::startPlayback(sample, sizeof(sample));
Serial.begin(9600);
pinMode(led1, OUTPUT);
digitalWrite(led1, LOW);
radio.begin();
radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_HIGH);
radio.stopListening();
}
void loop()
{
radio.startListening();
while (!radio.available());
radio.read(&buttonState, sizeof(buttonState));
Serial.println(buttonState);
if (buttonState == 1)
{
if (!samplePlayed)
{
digitalWrite(led1, LOW);
pcm::startPlayback(sample, sizeof(sample));
samplePlayed = true; // Set the flag to indicate the sample has been played
delay(400); // 200 ms Pause zwischen den Sendevorgängen
}
}
else
{
digitalWrite(led1, HIGH);
samplePlayed = false;
}
}
|