2021年8月18日 星期三

7seg 繞圓圈圈,一開機順時針慢轉1秒 壓一下逆時針快轉0.3秒 L(13pin都要blinking)

 unsigned long time1=0;

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

int seg7_table[] = {~0xfe, ~0xfd, ~0xfb, ~0xf7, ~0xef, ~0xdf};

int led_pin=13;

int delaytime = 1000;

int btn_pin = 9;

int num_val;

int cnt_val;

int even_odd;

void setup()

{

  pinMode(led_pin,OUTPUT);

  pinMode(btn_pin, INPUT);

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

  {

    pinMode(seg7_pin[i], OUTPUT);

    digitalWrite(seg7_pin[i], LOW);

  }

}

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

void outport(byte data)

{

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

  {

    if (data % 2 == 1)

      digitalWrite(seg7_pin[j], HIGH);

    else

      digitalWrite(seg7_pin[j], LOW);

    data = data / 2;

  }

}

void loop() 

{

  if(millis()-time1>500)

  {

    time1=millis();

    digitalWrite(led_pin,HIGH);delay(1000);

    digitalWrite(led_pin,LOW);delay(1000);

  }

  num_val = digitalRead(btn_pin);

  if (num_val == 0)

  {

    while (digitalRead(btn_pin) == LOW)

    {

      if (cnt_val == 0)

        cnt_val = 5;

      else

        cnt_val--;

      outport(seg7_table[cnt_val]);

      delay(300);

    }

  }

  else

  {

    if (cnt_val == 5)

      cnt_val = 0;

    else

      cnt_val++;

    outport(seg7_table[cnt_val]);

    delay(1000);

  }

}

沒有留言:

張貼留言

algorithm

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