#define POT 34 // Analog pin for the variable resistor
#define LED 26 // LED pin for sinking mode
float Vin = 0.0;
void TaskA(void *pt) {
while (1) {
int analogValue = analogRead(POT); // Read analog value from POT
Vin = (3.3 / 4095.0) * analogValue; // Convert to voltage (3.3V reference, 12-bit resolution)
delay(50); // Adjust delay as needed
}
}
void TaskB(void *pt) {
Serial.begin(9600); // Initialize serial communication at 9600 baud
while (1) {
Serial.print("Vin: ");
Serial.println(Vin); // Send the value of Vin through UART0
delay(1000); // Send every second (adjust as needed)
}
}
void TaskC(void *pt) {
while (1) {
if (Vin > 2.5) {
digitalWrite(LED, LOW); // Turn on LED (sinking mode)
} else {
digitalWrite(LED, HIGH); // Turn off LED
}
delay(200); // Adjust delay as needed
}
}
void setup() {
pinMode(POT, INPUT);
pinMode(LED, OUTPUT);
xTaskCreatePinnedToCore(TaskA, "TASKA", 2048, NULL, 3, NULL, 1);
xTaskCreatePinnedToCore(TaskB, "TASKB", 2048, NULL, 2, NULL, 1);
xTaskCreatePinnedToCore(TaskC, "TASKC", 1024, NULL, 1, NULL, 1);
}
void loop() {
// Nothing here
delay(10);
}