Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Blank PWM @ 50% on
- void setup() {
- pinMode(9,OUTPUT);
- }
- void loop() {
- analogWrite(9,127);
- }
- //-------------------------------------------------------------------------
- //PWM Controlled by pot
- int x=0;
- int y=0;
- void setup() {
- pinMode(9,OUTPUT);
- pinMode(A0,INPUT);
- }
- void loop() {
- x=(analogRead(A0));
- y=(map(x,0,1023,0,255));
- analogWrite(9,y);
- }
- //--------------------------------------------------------------
- //PWM with frequency control
- /*
- * Control Freq of PWM using PWM Library
- * my code: https://pastebin.com/eLWitAki
- * library: http://code.google.com/p/arduino-pwm-frequency-library/downloads/list
- */
- #include <PWM.h>
- int led = 9;
- int32_t frequency = 1000;
- void setup()
- {
- InitTimersSafe();
- bool success = SetPinFrequencySafe(led, frequency);
- if(success) {
- pinMode(13, OUTPUT);
- digitalWrite(13, HIGH);
- }
- }
- void loop()
- {
- pwmWrite(led, 127);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement