Skip to content

Commit 2a87d52

Browse files
committed
Added PWM Frequency Changer
Code part from here: http://playground.arduino.cc/Code/PwmFrequency
1 parent 90e5de8 commit 2a87d52

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

ldc500/ldc500.ino

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,30 @@ const int dht22Pin = 8;
3333
String inputString = ""; // a string to hold incoming data
3434
boolean stringComplete = false; // whether the string is complete
3535

36+
// Change PWM Frequency for Timer2.
37+
// Copied the relevant part from here:
38+
// http://playground.arduino.cc/Code/PwmFrequency
39+
void setPwmFrequency(int pin, int divisor) {
40+
byte mode;
41+
if(pin == 3 || pin == 11) {
42+
switch(divisor) {
43+
case 1: mode = 0x01; break;
44+
case 8: mode = 0x02; break;
45+
case 32: mode = 0x03; break;
46+
case 64: mode = 0x04; break;
47+
case 128: mode = 0x05; break;
48+
case 256: mode = 0x06; break;
49+
case 1024: mode = 0x7; break;
50+
default: return;
51+
}
52+
TCCR2B = TCCR2B & 0b11111000 | mode;
53+
}
54+
}
55+
3656
void setup() {
3757
pinMode(laserREM, OUTPUT);
3858
pinMode(laserMod, OUTPUT);
59+
setPwmFrequency(laserMod, 1);
3960
Serial.begin(115200);
4061
// reserve 200 bytes for the inputString:
4162
inputString.reserve(200);

0 commit comments

Comments
 (0)