writing speed is detected, and the model mayhem sets backlight according to

speed
This commit is contained in:
2008-11-15 23:56:58 +00:00
parent 84a5f01eb3
commit 516089168d
5 changed files with 84 additions and 0 deletions

View File

@ -70,6 +70,21 @@ void hardwareInit(void) {
PORTLEDS &= ~((1 << LEDNUM) | (1 << LEDCAPS) | (1 << LEDSCROLL) | (1 << LEDCOMP));
_delay_ms(50);
PORTLEDS |= ((1 << LEDNUM) | (1 << LEDCAPS) | (1 << LEDSCROLL) | (1 << LEDCOMP));
// initialize timer for pulse width modulation on backlight LED ports
// WGM13=1, WGM12=1, WGM11=1, WGM10=0 -> PWM mode 14
// COM1A1=1, COM1B1=1 -> OC1A and OC1B are set at the bottom and cleared on
// when the counter matches OCR1A or OCR1B
// CS10=1 -> prescaler 1
TCCR1A = (1 << COM1A1) | (1 << COM1B1) | (1 << WGM11);
TCCR1B = (1 << WGM13) | (1 << WGM12) | (1 << CS10);
// the pwm counter counts from 0 to this value
ICR1 = 0xffff;
// both LEDs are switched off on startup
OCR1A = 0xffff; // red
OCR1B = 0xffff; // green
}
/**
@ -101,6 +116,11 @@ void printMatrix(void) {
sendString("---");
}
void setSpeed(uint8_t speed) {
OCR1A = 0xffff - (speed * speed);
OCR1B = (speed * speed);
}
void setLeds(uint8_t LEDstate) {
if (LEDstate & LED_NUM) { // light up num lock
PORTLEDS &= ~(1 << LEDNUM);