wiki:7segduino-sample

Version 1 (modified by ysck, 7 years ago) (diff)

--

7segduino、スイッチサイエンス出荷時ののサンプルスケッチ。

#include <Sseg.h>
Sseg mySseg = Sseg(4,8,11,13,14,2,10,12,3,6,7,9);
long disp,wait,mode,counter1,counter2;
long wave[] = {
 0b00000000000000000000000000110001,
 0b00000000000000000000000101111011,
 0b00000000000000000011000111111111,
 0b00000000000000010111101111111111,
 0b00000000001100011111111111111111,
 0b00000001011110111111111111111111,
 0b00110001111111111111111111111111,
 0b01111011111111111111111111111111,
 0b11111111111111111111111111111110,
 0b11111111111111111111111111001110,
 0b11111111111111111111111010000100,
 0b11111111111111111100111000000000,
 0b11111111111111101000010000000000,
 0b11111111110011100000000000000000,
 0b11111110100001000000000000000000,
 0b11001110000000000000000000000000,
 0b10000100000000000000000000000001,
};
long number[] = {
 0b11111100,
 0b01100000,
 0b11011010,
 0b11110010,
 0b01100110,
 0b10110110,
 0b10111110,
 0b11100000,
 0b11111110,
 0b11110110,
};
void setup() {
 mySseg.begin();
 disp = 0;
 wait = 1;
 counter1 = 0;
 counter2 = 0;
 mode = 1;
}
void loop() {
 switch(mode) {
   case 0:  // wave
     disp = wave[counter1 % (sizeof(wave) / 4)];
     if(++counter1 >= (sizeof(wave) / 4) * 4) {
       disp = 0;
       wait = 1;
       counter1 = 0;
       mode++;
       mySseg.writeRawData(0,0,0,0);
       mySseg.updateWithDelay(100);
     } else break;
   case 1:  // countUP
     counter1 = (counter1 + 1773) % 10000;
     counter2++;
     if(counter2 >= 200) {
       disp = 0xfefefefe;
       wait = 100;
       mode++;
       counter1 = 0;
     } else {
       if(counter2 >= 160) counter1 = (counter1 % 10) + 8880;
       else if(counter2 >= 120) counter1 = (counter1 % 100) + 8800;
       else if(counter2 >= 80) counter1 = (counter1 % 1000) + 8000;
       disp = (number[(counter1 / 1000) % 10] << 24) +
(number[(counter1 / 100) % 10] << 16) + (number[(counter1 / 10) % 10]
<< 8) + number[counter1 % 10];
     }
     break;
   case 2:  // 8blink
     if((counter1 & 1) == 0) disp = 0b00000001000000010000000100000001;
     else disp = 0xfefefefe;
     if(++counter1 >= 12) {
       counter1 = 0;
       counter2 = 0;
       disp = 1;
       wait = 10;
       mode = 0;
     }
     break;
 }
 mySseg.writeRawData((disp >> 24) & 0xff,(disp >> 16) & 0xff,(disp >>
8) & 0xff,disp & 0xff);
 mySseg.updateWithDelay(wait);
}