2021年8月19日 星期四

計數到9暫停

 unsigned long time1 = 0;

int seg7_pin[] = {2, 3, 4, 5, 6, 7, 8};

unsigned char  seg7_table[] = {~0xc0, ~0xf9, ~0xa4, ~0xb0, ~0x99, ~0x92, ~0x82, ~0xf8, ~0x80, ~0x90};

int btn_pin=9;

int read_status;

int num_val;

void setup()

{

  pinMode(btn_pin,INPUT);

  for (int i = 0; i < 8; i++)

  {

    pinMode(seg7_pin[i], OUTPUT);

    digitalWrite(seg7_pin[i], LOW);

  }

}

//---------------------------------------

void outport(byte data)

{

  for (int j = 0; j < 7; j++)

  {

    if (data % 2 == 1)

      digitalWrite(seg7_pin[j], HIGH);

    else

      digitalWrite(seg7_pin[j], LOW);

    data=data/2;

    }

}

void loop()

{

//  read_status=digitalRead(btn_pin);

//  if(read_status==LOW)

//  {

//    delay(100);

//    while(digitalRead(btn_pin)==LOW);

//    num_val++;

//  }

  if(millis()-time1>=2000)

  {

    time1=millis();

    if(num_val==9)

     num_val=9;//計數到9就暫停

    else

    num_val++;

  }

  outport(seg7_table[num_val]);

}


沒有留言:

張貼留言

algorithm

 #include <iostream> #include <string.h> using namespace std; int main(int argc, char** argv)  { for(int j=2;j<=100;j++)//j...