Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const byte PWM_PIN = 10; // Digital Pin 5
- const byte PWM_PIN2 = 11; // Digital Pin 5
- byte pwm_value = 0;
- byte pwm_value2 = 0;
- void setup() {
- pinMode( PWM_PIN, OUTPUT );
- pinMode( PWM_PIN2, OUTPUT );
- //TCCR0A = (TCCR0A & ~((1 << COM0A1) | (1<< COM0A0))) | ((1 << COM0A1) | (1<< COM0A0));
- }
- void loop(){
- delay(900);
- setPwmFrequency(PWM_PIN, 1);
- setPwmFrequency(PWM_PIN2, 1);
- int value = 255/2;
- int Freq_speed = value;
- analogWrite(PWM_PIN,2.55*44);
- delayMicroseconds(5000);
- analogWrite(PWM_PIN2, 2.55*47); // same value for both
- delayMicroseconds(5000);
- TCCR1A |= bit (COM1A0); // inverting mode
- Serial.println(Freq_speed);
- delay(900);
- //invertAnalogWrite(PWM_PIN2, pwm_value2 );
- }
- void setPwmFrequency(int pin, int divisor) {
- byte mode;
- if(pin == 5 || pin == 6 || pin == 9 || pin == 10) {
- switch(divisor) {
- case 1: mode = 0x01; break;
- case 8: mode = 0x02; break;
- case 64: mode = 0x03; break;
- case 256: mode = 0x04; break;
- case 1024: mode = 0x05; break;
- default: return;
- }
- if(pin == 5 || pin == 6) {
- TCCR0B = TCCR0B & 0b11111000 | mode;
- } else {
- TCCR1B = TCCR1B & 0b11111000 | mode;
- }
- } else if(pin == 3 || pin == 11) {
- switch(divisor) {
- case 1: mode = 0x01; break;
- case 8: mode = 0x02; break;
- case 32: mode = 0x03; break;
- case 64: mode = 0x04; break;
- case 128: mode = 0x05; break;
- case 256: mode = 0x06; break;
- case 1024: mode = 0x7; break;
- default: return;
- }
- TCCR2B = TCCR2B & 0b11111000 | mode;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement