3 scrolling led on buttons
8 #include <dev/io.h> // needed for INB
12 int leds[NR_LEDS] = {8,9,10,11,12,13,14,15}; // the pin that the LED is attached to
13 // I don't really understand where this numbers are comming from yet :-(
14 int brightness = 0; // how bright the LED is
15 int fadeAmount = 5; // how many points to fade the LED by
30 Serial.println("sdo_isr");
32 digitalWrite( sdo_pin, sdo & mask ? HIGH : LOW );
36 Serial.println("sdi_isr");
38 if ( digitalRead( sdi_pin ) ) {
42 if (! mask) Serial.println(sdi_pin, HEX);
46 // the setup routine runs once when you press reset:
48 // declare pin 9 to be an output:
49 for(int i=0; i<NR_LEDS; i++) {
50 pinMode(leds[i], OUTPUT);
51 digitalWrite(leds[i], LOW);
54 analogWriteResolution(12);
57 Serial.println("setup");
59 attachInterrupt(sclk_pin, sdi_isr, RISING);
60 attachInterrupt(sclk_pin, sdo_isr, FALLING);
63 // the loop routine runs over and over again forever:
66 // set the brightness of pin 9:
69 if((mode & 8192) == 0)
71 analogWrite(leds[pos], brightness);
75 digitalWrite(leds[pos], (mode & 256) == 0 ? LOW : HIGH);
78 // change the brightness for next time through the loop:
79 brightness = brightness + fadeAmount;
81 // reverse the direction of the fading at the ends of the fade:
82 if (brightness == 0 || brightness == 4095) {
83 fadeAmount = -fadeAmount ;
84 Serial.print(micros());
86 Serial.println(count++);
93 if ( key != old_key && micros() - key_micros > 300) {
95 if (key & BTN_RIGHT && pos >= 0) pos--;
96 if (key & BTN_LEFT && pos < (NR_LEDS-1)) pos++;
97 if ( pos != old_pos ) {
100 Serial.print(" pos=");
102 Serial.print(" micros diff=");
103 Serial.println(micros()-key_micros);
104 digitalWrite(leds[old_pos], LOW);
105 digitalWrite(leds[pos], HIGH);
107 key_micros = micros();
111 // wait for 30 milliseconds to see the dimming effect