24 lines
617 B
C++
24 lines
617 B
C++
const int potPin = A0; // analog pin for potentiometer
|
|
const int pwmPin = 6; // PWM pin connected to the transistor gate
|
|
const int pwm2Pin = 5;
|
|
|
|
void setup() {
|
|
pinMode(pwmPin, OUTPUT); // set pwmPin as output
|
|
pinMode(pwm2Pin, OUTPUT);
|
|
}
|
|
|
|
void loop() {
|
|
// read the potentiometer value (0-1023)
|
|
int potValue = analogRead(potPin);
|
|
|
|
// map the potentiometer value to a PWM value (0-255)
|
|
int pwmValue = map(potValue, 0, 1023, 0, 255);
|
|
|
|
// write the PWM value to the PWM pin
|
|
analogWrite(pwmPin, pwmValue);
|
|
analogWrite(pwm2Pin, pwmValue);
|
|
|
|
// slight delay to stabilize readings
|
|
delay(10);
|
|
}
|