#include <Arduino.h>
#define ADC_PIN PA0 // ADC Input Pin (Potentiometer)
#define PWM_PIN PA7 // Simulated PWM Output (For Debugging)
#define BAUD_RATE 9600 // UART Baud Rate
void setup() {
Serial.begin(BAUD_RATE); // Initialize UART
pinMode(ADC_PIN, INPUT);
pinMode(PWM_PIN, OUTPUT); // Even though Wokwi does not support PWM, we define the pin
}
void loop() {
// Read ADC Value (12-bit: 0-4095)
int adcValue = analogRead(ADC_PIN);
// Convert ADC to Voltage (Assuming 3.3V Reference)
float voltage = (adcValue / 4095.0) * 3.3;
// Simulated PWM Duty Cycle (Mapping ADC to 8-bit PWM)
int pwmOutput = map(adcValue, 0, 4095, 0, 255);
// Simulate PWM via Serial Monitor (Since Wokwi doesn’t support analogWrite on STM32)
Serial.print("ADC Value: "); Serial.print(adcValue);
Serial.print(" | Voltage: "); Serial.print(voltage, 2);
Serial.print("V | Simulated PWM Duty Cycle: "); Serial.print((pwmOutput / 255.0) * 100);
Serial.println("%");
delay(500);
}Loading
st-nucleo-l031k6
st-nucleo-l031k6