Added Basic Melody-Handling Task and temp-task for testing
This commit is contained in:
@@ -1 +1,86 @@
|
|||||||
// MELODY PLAYBACK WILL BE HANDLED HERE
|
// MELODY PLAYBACK WILL BE HANDLED HERE
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <Adafruit_PCF8574.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
|
||||||
|
#define PCF8574_ADDR 0x24 // Change the address if it's different
|
||||||
|
Adafruit_PCF8574 pcf8574; // Create an instance of the PCF8574 class
|
||||||
|
|
||||||
|
extern volatile bool playing;
|
||||||
|
|
||||||
|
void bellEngine(void *parameter);
|
||||||
|
void tempEngine(void *parameter);
|
||||||
|
|
||||||
|
void bellEngine(void *parameter) {
|
||||||
|
|
||||||
|
uint16_t melodyMap[5500];
|
||||||
|
|
||||||
|
// read the melody from file and store it in RAM
|
||||||
|
File melody_file = SPIFFS.open("/melody1.bin", "r");
|
||||||
|
if (!melody_file) {
|
||||||
|
Serial.println("failed to open file");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (;;){
|
||||||
|
Serial.println("Initializing Melody Read");
|
||||||
|
|
||||||
|
std::vector<uint16_t> melody;
|
||||||
|
|
||||||
|
size_t fileSize = melody_file.size();
|
||||||
|
size_t steps = fileSize / 2;
|
||||||
|
melody.resize(steps);
|
||||||
|
|
||||||
|
Serial.print("Debuggin - FileSize: ");
|
||||||
|
Serial.print(fileSize);
|
||||||
|
Serial.print(" Steps: ");
|
||||||
|
Serial.println(steps);
|
||||||
|
Serial.println("Continuing with Assignment");
|
||||||
|
|
||||||
|
for (size_t i=0; i<steps; i++){
|
||||||
|
melody[i] = melody_file.read() << 8 | melody_file.read();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i=0; i<steps; i++){
|
||||||
|
Serial.print("Current Step: ");
|
||||||
|
Serial.print(i);
|
||||||
|
Serial.print(" Current Beat in HEX: ");
|
||||||
|
Serial.println(melody[i], HEX);
|
||||||
|
}
|
||||||
|
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(5000));
|
||||||
|
Serial.println("Closing File");
|
||||||
|
melody_file.close();
|
||||||
|
|
||||||
|
UBaseType_t highWaterMark = uxTaskGetStackHighWaterMark(NULL);
|
||||||
|
Serial.print("Stack high water mark: ");
|
||||||
|
Serial.println(highWaterMark);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void tempEngine(void *parameter){
|
||||||
|
|
||||||
|
// setup
|
||||||
|
Wire.begin(4, 15);
|
||||||
|
pcf8574.begin(PCF8574_ADDR);
|
||||||
|
pcf8574.pinMode(0, OUTPUT);
|
||||||
|
|
||||||
|
for (;;){
|
||||||
|
//loop
|
||||||
|
if (playing) {
|
||||||
|
Serial.println("DING!");
|
||||||
|
pcf8574.digitalWrite(0, LOW);
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(500));
|
||||||
|
pcf8574.digitalWrite(0, HIGH);
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(500));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
26
vesper.ino
26
vesper.ino
@@ -28,6 +28,10 @@ volatile bool playing = false;
|
|||||||
#include "melody_handling.hpp"
|
#include "melody_handling.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
TaskHandle_t myTaskHandle = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
// Initialize Serial Communication (for debuggin)
|
// Initialize Serial Communication (for debuggin)
|
||||||
@@ -48,6 +52,28 @@ void setup()
|
|||||||
ConnectWiFi_STA();
|
ConnectWiFi_STA();
|
||||||
delay(1000);
|
delay(1000);
|
||||||
|
|
||||||
|
xTaskCreatePinnedToCore(
|
||||||
|
bellEngine, // Task function
|
||||||
|
"bellEngine", // Task name
|
||||||
|
8192, // Stack size
|
||||||
|
NULL, // Task input parameters
|
||||||
|
1, // Task priority, be carefull when changing this
|
||||||
|
&myTaskHandle, // Task handle, add one if you want control over the task (resume or suspend the task)
|
||||||
|
1 // Core to run the task on
|
||||||
|
);
|
||||||
|
|
||||||
|
vTaskSuspend(myTaskHandle);
|
||||||
|
|
||||||
|
xTaskCreatePinnedToCore(
|
||||||
|
tempEngine, // Task function
|
||||||
|
"tempEngine", // Task name
|
||||||
|
8192, // Stack size
|
||||||
|
NULL, // Task input parameters
|
||||||
|
1, // Task priority, be carefull when changing this
|
||||||
|
NULL, // Task handle, add one if you want control over the task (resume or suspend the task)
|
||||||
|
1 // Core to run the task on
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
|
|||||||
Reference in New Issue
Block a user