Changes between Initial Version and Version 1 of 7segduino-sample


Ignore:
Timestamp:
Apr 19, 2012 1:04:22 PM (8 years ago)
Author:
ysck
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • 7segduino-sample

    v1 v1  
     17segduino、スイッチサイエンス出荷時ののサンプルスケッチ。
     2
     3{{{
     4#include <Sseg.h>
     5Sseg mySseg = Sseg(4,8,11,13,14,2,10,12,3,6,7,9);
     6long disp,wait,mode,counter1,counter2;
     7long wave[] = {
     8 0b00000000000000000000000000110001,
     9 0b00000000000000000000000101111011,
     10 0b00000000000000000011000111111111,
     11 0b00000000000000010111101111111111,
     12 0b00000000001100011111111111111111,
     13 0b00000001011110111111111111111111,
     14 0b00110001111111111111111111111111,
     15 0b01111011111111111111111111111111,
     16 0b11111111111111111111111111111110,
     17 0b11111111111111111111111111001110,
     18 0b11111111111111111111111010000100,
     19 0b11111111111111111100111000000000,
     20 0b11111111111111101000010000000000,
     21 0b11111111110011100000000000000000,
     22 0b11111110100001000000000000000000,
     23 0b11001110000000000000000000000000,
     24 0b10000100000000000000000000000001,
     25};
     26long number[] = {
     27 0b11111100,
     28 0b01100000,
     29 0b11011010,
     30 0b11110010,
     31 0b01100110,
     32 0b10110110,
     33 0b10111110,
     34 0b11100000,
     35 0b11111110,
     36 0b11110110,
     37};
     38void setup() {
     39 mySseg.begin();
     40 disp = 0;
     41 wait = 1;
     42 counter1 = 0;
     43 counter2 = 0;
     44 mode = 1;
     45}
     46void loop() {
     47 switch(mode) {
     48   case 0:  // wave
     49     disp = wave[counter1 % (sizeof(wave) / 4)];
     50     if(++counter1 >= (sizeof(wave) / 4) * 4) {
     51       disp = 0;
     52       wait = 1;
     53       counter1 = 0;
     54       mode++;
     55       mySseg.writeRawData(0,0,0,0);
     56       mySseg.updateWithDelay(100);
     57     } else break;
     58   case 1:  // countUP
     59     counter1 = (counter1 + 1773) % 10000;
     60     counter2++;
     61     if(counter2 >= 200) {
     62       disp = 0xfefefefe;
     63       wait = 100;
     64       mode++;
     65       counter1 = 0;
     66     } else {
     67       if(counter2 >= 160) counter1 = (counter1 % 10) + 8880;
     68       else if(counter2 >= 120) counter1 = (counter1 % 100) + 8800;
     69       else if(counter2 >= 80) counter1 = (counter1 % 1000) + 8000;
     70       disp = (number[(counter1 / 1000) % 10] << 24) +
     71(number[(counter1 / 100) % 10] << 16) + (number[(counter1 / 10) % 10]
     72<< 8) + number[counter1 % 10];
     73     }
     74     break;
     75   case 2:  // 8blink
     76     if((counter1 & 1) == 0) disp = 0b00000001000000010000000100000001;
     77     else disp = 0xfefefefe;
     78     if(++counter1 >= 12) {
     79       counter1 = 0;
     80       counter2 = 0;
     81       disp = 1;
     82       wait = 10;
     83       mode = 0;
     84     }
     85     break;
     86 }
     87 mySseg.writeRawData((disp >> 24) & 0xff,(disp >> 16) & 0xff,(disp >>
     888) & 0xff,disp & 0xff);
     89 mySseg.updateWithDelay(wait);
     90}
     91}}}