output gets put in booleans and send in array
This commit is contained in:
@@ -1,16 +1,24 @@
|
|||||||
|
#include <ArduinoJson.h>
|
||||||
|
#include <ArduinoJson.hpp>
|
||||||
|
|
||||||
const int buttonPinUp = 9; // the number of the pushbutton pin
|
const int buttonPinUp = 9; // the number of the pushbutton pin
|
||||||
const int buttonPinRight = 10; // the number of the pushbutton pin
|
const int buttonPinRight = 10; // the number of the pushbutton pin
|
||||||
const int buttonPinDown = 11; // the number of the pushbutton pin
|
const int buttonPinDown = 11; // the number of the pushbutton pin
|
||||||
const int buttonPinLeft = 12; // the number of the pushbutton pin
|
const int buttonPinLeft = 12; // the number of the pushbutton pin
|
||||||
const int buttonPinDodge = 14;
|
const int buttonPinDodge = 14;
|
||||||
const int buttonPinPause = 13;
|
const int buttonPinPause = 13;
|
||||||
int buttonStateUp = 0;
|
int buttonStateUp = 0;
|
||||||
|
int buttonStateRight = 0;
|
||||||
int buttonStateDown = 0;
|
int buttonStateDown = 0;
|
||||||
int buttonStateLeft = 0;
|
int buttonStateLeft = 0;
|
||||||
int buttonStateRight = 0;
|
|
||||||
int buttonStateDodge = 0;
|
int buttonStateDodge = 0;
|
||||||
int buttonStatePause = 0;
|
int buttonStatePause = 0;
|
||||||
|
bool boolUp = false;
|
||||||
|
bool boolRight = false;
|
||||||
|
bool boolDown = false;
|
||||||
|
bool boolLeft = false;
|
||||||
|
bool boolDodge = false;
|
||||||
|
bool boolPause = false;
|
||||||
|
|
||||||
// variables will change:
|
// variables will change:
|
||||||
|
|
||||||
@@ -23,10 +31,15 @@ void setup() {
|
|||||||
pinMode(buttonPinDodge, INPUT);
|
pinMode(buttonPinDodge, INPUT);
|
||||||
pinMode(buttonPinPause, INPUT);
|
pinMode(buttonPinPause, INPUT);
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
boolUp = false;
|
||||||
|
boolRight = false;
|
||||||
|
boolDown = false;
|
||||||
|
boolLeft = false;
|
||||||
|
boolDodge = false;
|
||||||
|
boolPause = false;
|
||||||
// read the state of the pushbutton value:
|
// read the state of the pushbutton value:
|
||||||
buttonStateUp = digitalRead(buttonPinUp);
|
buttonStateUp = digitalRead(buttonPinUp);
|
||||||
buttonStateRight = digitalRead(buttonPinRight);
|
buttonStateRight = digitalRead(buttonPinRight);
|
||||||
@@ -37,24 +50,27 @@ void loop() {
|
|||||||
|
|
||||||
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
|
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
|
||||||
if (buttonStateUp == HIGH) {
|
if (buttonStateUp == HIGH) {
|
||||||
Serial.println("Up");
|
boolUp = true;
|
||||||
}
|
}
|
||||||
else if (buttonStateRight == HIGH) {
|
if (buttonStateRight == HIGH) {
|
||||||
Serial.println("Right");
|
boolRight = true;
|
||||||
}
|
}
|
||||||
else if (buttonStateDown == HIGH) {
|
if (buttonStateDown == HIGH) {
|
||||||
Serial.println("Down");
|
boolDown = true;
|
||||||
}
|
}
|
||||||
else if (buttonStateLeft == HIGH) {
|
if (buttonStateLeft == HIGH) {
|
||||||
Serial.println("Left");
|
boolLeft = true;
|
||||||
}
|
|
||||||
else if (buttonStateDodge == HIGH) {
|
|
||||||
Serial.println("Dodge");
|
|
||||||
}
|
}
|
||||||
else if (buttonStatePause == HIGH) {
|
if (buttonStateDodge == HIGH) {
|
||||||
Serial.println("Pause");
|
boolDodge = true;
|
||||||
}
|
}
|
||||||
else {
|
if (buttonStatePause == HIGH) {
|
||||||
Serial.println("geen button");
|
boolPause = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
String inputOutput = String("[") + boolUp + "," + boolRight + "," + boolDown + "," + boolLeft + "," + boolDodge + "," + boolPause + "]\n";
|
||||||
|
|
||||||
|
if (inputOutput) {
|
||||||
|
Serial.println(inputOutput);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user