/* * Copyright 2012 (C) Christian Franke * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with This program. If not, see . * */ #include #include #include #include volatile uint16_t value_red = 3072; volatile uint16_t value_green = 2048; volatile uint16_t value_blue = 1024; void pwm_set_rgb(uint8_t r, uint8_t g, uint8_t b) { value_red = r << 4; value_green = g << 4; value_blue = b << 4; } void pwm_worker_loop(void) { for (;;) { if (value_red) PORTA |= (1 << PA0); if (value_green) PORTA |= (1 << PA1); if (value_blue) PORTA |= (1 << PA2); for (uint16_t i = 0; i < 4096; i++) { if (value_red < i) PORTA &= ~(1 << PA0); if (value_green < i) PORTA &= ~(1 << PA1); if (value_blue < i) PORTA &= ~(1 << PA2); } } } void pwm_init(void) { PORTA = 0x00; DDRA = (1 << PA0) | (1 << PA1) | (1 << PA2); }