First init.
This commit is contained in:
23
PWM_Test/PWM_Test.ino
Normal file
23
PWM_Test/PWM_Test.ino
Normal file
@@ -0,0 +1,23 @@
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user