通过按下向下按钮将变量“ Richtung”更改为0

时间:2019-12-31 01:47:59

标签: c++ arduino arduino-uno arduino-c++

我正在使用带有4个按钮的Arduino Uno,并且试图通过按下向下按钮将变量“ Richtung”更改为0。我对其他3个程序进行了编程,它们运行良好。

#include <Arduino.h>
#include <Adafruit_GFX.h>
#include <Adafruit_LEDBackpack.h>

Adafruit_8x8matrix matrix = Adafruit_8x8matrix();

int IO_BUTTON_UP = 4;
int AIO_BUTTON_MATRIX = 3;
int IO_BUTTON_DOWN = 5;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println("Matrix8x8");
  Serial.println("<Autor>");
  matrix.begin(0x70);
  matrix.setBrightness(1);
  pinMode(IO_BUTTON_UP, INPUT);
  pinMode(AIO_BUTTON_MATRIX, INPUT);
  pinMode(IO_BUTTON_DOWN, INPUT);
}

int richtung = 0;

void loop() {

  int valButtonMatrix = analogRead(AIO_BUTTON_MATRIX);
  if (digitalRead(IO_BUTTON_DOWN) == 2){
    richtung = 0;
  }
  if (valButtonMatrix > 600){ //Rechter Button
    richtung = 1;
  } else if (valButtonMatrix > 400) { //Linker Button
    richtung = 3;
  }
  if (digitalRead(IO_BUTTON_UP) == 1){
    richtung = 2; 
  }
}

0 个答案:

没有答案