2021年8月21日 星期六

按下去沒反應可能電位有問題,用邏輯探測棒debug 按一下1357跑 再按一下8642跑

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

int j = -2;

int direct = 0;

int btn_pin = 10;

int val = 1;

int r=9;

void setup()

{

  Serial.begin(9600);

  pinMode(btn_pin, INPUT);

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

  {

    pinMode(led_pin[i], OUTPUT);

  }

}


void loop()

{

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

  {

    digitalWrite(led_pin[k], LOW);

  }

  val = digitalRead(btn_pin);//按下去沒反應可能電位有問題,用邏輯探測棒debug

  if (val == 0)

  {

    val = digitalRead(btn_pin);

    delay(1000);

    while (digitalRead(btn_pin) == LOW);

    direct = !direct;

  }

  if (direct == 0)//由左往右跑每次+2

  {

     if (L == 6)

      L = 0;

    else

      L = L + 2;

    digitalWrite(led_pin[L], HIGH);

    delay(1000);

  }

  else

  {

     if (r == 1)//由右往左跑,每次-2

      r = 7;

    else

      r = r - 2;

    digitalWrite(led_pin[r], HIGH);

    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...