LLMind/apply_stimulation/apply_stimulation.ino

47 lines
1.4 KiB
Arduino
Raw Normal View History

2024-10-17 19:24:48 +03:00
#include <avr/pgmspace.h>
#include "stimulation_pattern.h"
2024-10-19 00:16:28 +03:00
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
2024-10-17 19:24:48 +03:00
void setup() {
pinMode(stimulationPin, OUTPUT);
2024-10-19 00:16:28 +03:00
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);
}
2024-10-17 19:24:48 +03:00
}
void loop() {
for (uint16_t i = 0; i < PATTERN_SIZE; i++) {
uint8_t stimulationValue = pgm_read_byte(&stimulation_pattern[i]);
2024-10-19 00:16:28 +03:00
writeOutput(stimulationValue);
// Print the value based on the mode
if (USE_DIGITAL) {
Serial.println(analogToDigital(stimulationValue) ? 255 : 0);
} else {
Serial.println(stimulationValue);
}
2024-10-17 19:24:48 +03:00
2024-10-19 00:16:28 +03:00
delayMicroseconds(delayBetweenStimulations);
2024-10-17 19:24:48 +03:00
}
2024-10-19 00:16:28 +03:00
// Remove the long delay at the end to continuously send data
2024-10-17 19:24:48 +03:00
}