/* scrolling led on buttons */ extern "C" { #include // needed for INB } #define NR_LEDS 8 int leds[NR_LEDS] = {8,9,10,11,12,13,14,15}; // the pin that the LED is attached to // I don't really understand where this numbers are comming from yet :-( int brightness = 0; // how bright the LED is int fadeAmount = 5; // how many points to fade the LED by int count = 0; int pos = 0; int old_key = -1; int key_micros = 0; int sdi = 0; int sdo = 0xAA; int mask = 0x01; int sdi_pin = 10; int sdo_pin = 9; int sclk_pin = 8; void sdo_isr(void) { Serial.println("sdo_isr"); if (! mask) return; digitalWrite( sdo_pin, sdo & mask ? HIGH : LOW ); } void sdi_isr(void) { Serial.println("sdi_isr"); if (! mask) return; if ( digitalRead( sdi_pin ) ) { sdi_pin |= mask; } mask <<= 1; if (! mask) Serial.println(sdi_pin, HEX); } // the setup routine runs once when you press reset: void setup() { // declare pin 9 to be an output: for(int i=0; i 300) { old_key = key; if (key & BTN_RIGHT && pos >= 0) pos--; if (key & BTN_LEFT && pos < (NR_LEDS-1)) pos++; if ( pos != old_pos ) { Serial.print("key "); Serial.print(key); Serial.print(" pos="); Serial.print(pos); Serial.print(" micros diff="); Serial.println(micros()-key_micros); digitalWrite(leds[old_pos], LOW); digitalWrite(leds[pos], HIGH); } key_micros = micros(); } // wait for 30 milliseconds to see the dimming effect delay(1); }