viszualizers and digital output

This commit is contained in:
unknown
2024-10-19 00:16:28 +03:00
parent 96d23c1b59
commit 62f1861de0
4 changed files with 157 additions and 10 deletions

View File

@@ -1,26 +1,46 @@
#include <avr/pgmspace.h>
#include "stimulation_pattern.h"
const int stimulationPin = 5;
const int delayBetweenStimulations = 10; // milliseconds
const bool DEBUG = true; // Set to true to enable serial output
const bool USE_DIGITAL = true; // Set to false to use analog output
const int stimulationPin = 5; // PWM-capable pin
const unsigned long delayBetweenStimulations = 1000; // microseconds (1ms delay for more stable serial transmission)
const int threshold = 50; // Threshold for converting analog to digital
void setup() {
pinMode(stimulationPin, OUTPUT);
Serial.begin(9600);
Serial.begin(115200); // Increased baud rate for faster output
}
// Function to convert analog value to digital
bool analogToDigital(uint8_t analogValue) {
return analogValue >= threshold;
}
// Function to write output (digital or analog)
void writeOutput(uint8_t value) {
if (USE_DIGITAL) {
digitalWrite(stimulationPin, analogToDigital(value) ? HIGH : LOW);
} else {
analogWrite(stimulationPin, value);
}
}
void loop() {
for (uint16_t i = 0; i < PATTERN_SIZE; i++) {
uint8_t stimulationValue = pgm_read_byte(&stimulation_pattern[i]);
analogWrite(stimulationPin, stimulationValue);
// Print the current stimulation value for debugging
Serial.print("Applying stimulation: ");
Serial.println(stimulationValue);
writeOutput(stimulationValue);
delay(delayBetweenStimulations);
// Print the value based on the mode
if (USE_DIGITAL) {
Serial.println(analogToDigital(stimulationValue) ? 255 : 0);
} else {
Serial.println(stimulationValue);
}
delayMicroseconds(delayBetweenStimulations);
}
// Add a longer delay at the end of each complete pattern
delay(1000);
// Remove the long delay at the end to continuously send data
}