└── MotionPumpkin └── MotionPumpkin.ino /MotionPumpkin/MotionPumpkin.ino: -------------------------------------------------------------------------------- 1 | //code by bitluni (send me a high five if you like the code) 2 | 3 | #include "sample.h" 4 | //replace this include file by your header file generated by the conversion tool found 5 | //here: https://bitluni.net/wp-content/uploads/2018/01/Audio2Header.html 6 | 7 | #include 8 | #include 9 | 10 | const int MOTION_PIN = 4; 11 | const int LED_PIN = 15; 12 | const int LED_COUNT = 10; 13 | 14 | bool play = false; 15 | 16 | Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ400); 17 | 18 | void showTask(void *param) 19 | { 20 | while(true) 21 | { 22 | if(play) 23 | { 24 | int c = ((millis() >> 5) & 1) * 255; 25 | for(int i = 0; i < LED_COUNT; i++) 26 | { 27 | strip.setPixelColor(i, strip.Color(c, c, c)); 28 | } 29 | strip.show(); 30 | } 31 | else 32 | { 33 | for(int i = 0; i < LED_COUNT; i++) 34 | { 35 | float f = sin(millis() * 0.002f + (i * 0.628)); 36 | int c = max(0, (int)(f * f * f * 255)); 37 | strip.setPixelColor(i, strip.Color(0, c, 0)); 38 | } 39 | strip.show(); 40 | } 41 | delay(10); 42 | } 43 | } 44 | 45 | void setup() 46 | { 47 | pinMode(LED_PIN, OUTPUT); 48 | pinMode(MOTION_PIN, INPUT); 49 | Serial.begin(115200); 50 | dac_output_enable(DAC_CHANNEL_1); 51 | dac_output_voltage(DAC_CHANNEL_1, 128); 52 | strip.begin(); 53 | strip.show(); 54 | strip.setBrightness(255); 55 | TaskHandle_t xHandle = NULL; 56 | xTaskCreatePinnedToCore(showTask, "show", 5000, 0, ( 2 | portPRIVILEGE_BIT ), &xHandle, 0); 57 | } 58 | 59 | void loop() 60 | { 61 | static unsigned long startTime = 0; 62 | static unsigned long coolDown = 0; 63 | if(digitalRead(MOTION_PIN) && !play && millis() >= coolDown) 64 | { 65 | play = true; 66 | startTime = micros(); 67 | } 68 | if(play) 69 | { 70 | unsigned long pos = (micros() - startTime) / (1000000 / sampleRate); 71 | if(pos < sampleCount) 72 | dac_output_voltage(DAC_CHANNEL_1, (int)samples[pos] + 128); 73 | else 74 | { 75 | play = false; 76 | coolDown = millis() + 5000; 77 | } 78 | } 79 | } 80 | --------------------------------------------------------------------------------