47 lines
1.4 KiB
C++
47 lines
1.4 KiB
C++
#include <avr/pgmspace.h>
|
|
#include "stimulation_pattern.h"
|
|
|
|
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(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]);
|
|
|
|
writeOutput(stimulationValue);
|
|
|
|
// Print the value based on the mode
|
|
if (USE_DIGITAL) {
|
|
Serial.println(analogToDigital(stimulationValue) ? 255 : 0);
|
|
} else {
|
|
Serial.println(stimulationValue);
|
|
}
|
|
|
|
delayMicroseconds(delayBetweenStimulations);
|
|
}
|
|
|
|
// Remove the long delay at the end to continuously send data
|
|
}
|