#define DUTY_INC 0x80 char buff[20]; uint16_t duty; const byte pwmPin = 11; // Arduino pin 9 (OC1A) supports Timer1 PWM void setup() { Serial.begin(9600); pinMode(pwmPin, OUTPUT); // Set the PWM pin as an output Serial.println("Tutorial 4"); Serial.println("Color Cube"); Serial.println("Skyboard v2"); Serial.println("Pin 11 to the LED"); Serial.print("> "); // Configure Timer1 for Fast PWM mode, non-inverting output // WGM13, WGM12, WGM11, WGM10 = 1110 for Fast PWM with ICR1 as TOP TCCR1A = (1<= DUTY_INC) { duty -= DUTY_INC; OCR1A = duty; Serial.print("The duty cycle is "); Serial.print(duty); sprintf(buff,"/%d",ICR1); Serial.println(buff); } else { Serial.println("Duty cycle at minimum"); } break; case 'P': if (duty <= ICR1 - DUTY_INC) { duty += DUTY_INC; OCR1A = duty; Serial.print("The duty cycle is "); Serial.print(duty); sprintf(buff,"/%d",ICR1); Serial.println(buff); } else { Serial.println("Duty cycle at maximum"); } break; case 'z': for (uint8_t i = 0; i < 40; i++) Serial.println(); break; default: Serial.print("Unknown key "); Serial.println(cmd); break; } Serial.print("> "); } }