From 31b7bb54af88579f9f41f72af7ea55d9b6cdff55 Mon Sep 17 00:00:00 2001 From: sam Date: Wed, 22 Nov 2023 13:40:50 +0100 Subject: [PATCH] output gets put in booleans and send in array --- .../sketch_nov21a/sketch_nov21a.ino | 56 ++++++++++++------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/arduino/Serial button test/sketch_nov21a/sketch_nov21a.ino b/arduino/Serial button test/sketch_nov21a/sketch_nov21a.ino index 1a0f0f0..89c0a26 100644 --- a/arduino/Serial button test/sketch_nov21a/sketch_nov21a.ino +++ b/arduino/Serial button test/sketch_nov21a/sketch_nov21a.ino @@ -1,16 +1,24 @@ +#include +#include -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 buttonPinDown = 11; // the number of the pushbutton pin -const int buttonPinLeft = 12; // 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 buttonPinDodge = 14; const int buttonPinPause = 13; int buttonStateUp = 0; +int buttonStateRight = 0; int buttonStateDown = 0; int buttonStateLeft = 0; -int buttonStateRight = 0; int buttonStateDodge = 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: @@ -23,10 +31,15 @@ void setup() { pinMode(buttonPinDodge, INPUT); pinMode(buttonPinPause, INPUT); Serial.begin(9600); - } void loop() { + boolUp = false; + boolRight = false; + boolDown = false; + boolLeft = false; + boolDodge = false; + boolPause = false; // read the state of the pushbutton value: buttonStateUp = digitalRead(buttonPinUp); buttonStateRight = digitalRead(buttonPinRight); @@ -37,24 +50,27 @@ void loop() { // check if the pushbutton is pressed. If it is, the buttonState is HIGH: if (buttonStateUp == HIGH) { - Serial.println("Up"); + boolUp = true; } - else if (buttonStateRight == HIGH) { - Serial.println("Right"); + if (buttonStateRight == HIGH) { + boolRight = true; } - else if (buttonStateDown == HIGH) { - Serial.println("Down"); + if (buttonStateDown == HIGH) { + boolDown = true; } - else if (buttonStateLeft == HIGH) { - Serial.println("Left"); - } - else if (buttonStateDodge == HIGH) { - Serial.println("Dodge"); + if (buttonStateLeft == HIGH) { + boolLeft = true; } - else if (buttonStatePause == HIGH) { - Serial.println("Pause"); - } - else { - Serial.println("geen button"); + if (buttonStateDodge == HIGH) { + boolDodge = true; + } + if (buttonStatePause == HIGH) { + boolPause = true; + } + + String inputOutput = String("[") + boolUp + "," + boolRight + "," + boolDown + "," + boolLeft + "," + boolDodge + "," + boolPause + "]\n"; + + if (inputOutput) { + Serial.println(inputOutput); } }