Changes between Version 4 and Version 5 of 7segduino


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

--

Legend:

Unmodified
Added
Removed
Modified
  • 7segduino

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