Changes between Version 1 and Version 2 of 7segduino


Ignore:
Timestamp:
Apr 19, 2012 12:57:59 PM (12 years ago)
Author:
ysck
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • 7segduino

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