Skip to content

Instantly share code, notes, and snippets.

@giljr
Last active April 22, 2017 21:56
Show Gist options
  • Save giljr/a858373c4f69a4bc5b732e0de60f81f8 to your computer and use it in GitHub Desktop.
Save giljr/a858373c4f69a4bc5b732e0de60f81f8 to your computer and use it in GitHub Desktop.
s
const int Red = 0;
const int Green = 1;
const int Blue = 2;
volatile uint8_t* Port[] = {&OCR0A, &OCR0B, &OCR1B};
void setup() {
DDRB |= (1 << DDB4) | (1 << DDB1) | (1 << DDB0);
TCCR0A = 3 << COM0A0 | 3 << COM0B0 | 3 << WGM00;
TCCR0B = 0 << WGM02 | 3 << CS00;
TCCR1 = 0 << PWM1A | 3 << COM1A0 | 7 << CS10;
GTCCR = 1 << PWM1B | 3 << COM1B0;
}
void SetColour (int colour, int intensity) {
*Port[colour] = 255 - intensity;
}
void loop() {
for (int colour = 0; colour < 3; colour++) {
SetColour((colour + 2) % 3, 0);
for (int i = 0; i <= 255; i++) {
SetColour((colour + 1) % 3, i);
SetColour(colour, 255 - i);
delay(1);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment