I am trying to get the buttons on the master controller more functional. Here is the setup:
Two microcontrollers, 1 Uno and 1 Mega. The joystick and buttons are on the Uno (master) which controls the Mega(Slave) via a radio data stream. So, if I push the E button on the Uno, I can see that button press in the serial monitor on the Mega. Either a zero or a 1.
How do you latch that button press from the Slave (Mega) side? So its on when pressed once, off when pressed again? Or do I have to do it from the Master side? (which makes more sense?)
It made sense to me to do that when the button is on the microcontroller. But the way I would prefer to do it is on the slave where the rest of the programming (mostly) resides.
btnEValue is the variable that carries through the radio array to the slave. In this case, you can't do a digitalRead of the pin, rather, its just there. Easy for me to get confused.
Deve:
It made sense to me to do that when the button is on the microcontroller. But the way I would prefer to do it is on the slave where the rest of the programming (mostly) resides.
btnEValue is the variable that carries through the radio array to the slave. In this case, you can't do a digitalRead of the pin, rather, its just there. Easy for me to get confused.
The slave must have that received value stored in a variable before the board prints/outputs that value.
Don't see why you can't toggle that value before you output it.
We probably need to see a diagram and the code of the slave.
Leo..
This is the code for the Uno that has the Funduino Joystick Shield on it..
#include <SPI.h> /* Serial Peripheral Interface Library (required) */
#include <RF24.h> /* NRF24 Radio Library */
const int initCEPin = 9; /* Chip Enable Digital Pin 9 */
const int initCSNPin = 10; /* SPI Chip Select Digital Pin 10 */
const int xAxis = A0; /* X Axis (Horizontal) */
const int yAxis = A1; /* Y Axis (Vertical) */
const int buttonA = 2; /* A button (top) */
const int buttonB = 3; /* B button (right) */
const int buttonC = 4; /* C button (bottom) */
const int buttonD = 5; /* D button (left) */
const int buttonE = 6; /* E button (bottom right) */
const int buttonF = 7; /* F button (bottom left) */
const int joySW = 8; /* ThumbStick Switch */
const uint64_t pipe = 0xE8E8F0F0E1LL; /* Radio's addressing system */
RF24 radio(initCEPin, initCSNPin); /* Initialize the Radio */
int smartStream[9]; /* Create Communication Array for all functions */
void setup() {
Serial.begin(115200);
radio.begin(); /* Open the Radio for communication */
radio.openWritingPipe(pipe); /* Open two-way Comm to the Slave Mega2560 */
pinMode(buttonA, INPUT);
pinMode(buttonB, INPUT); /* Only Digital pins are required to be defined here */
pinMode(buttonC, INPUT); /* The Analog Thumbstick is exempt */
pinMode(buttonD, INPUT);
pinMode(buttonE, INPUT);
pinMode(buttonF, INPUT);
pinMode (joySW, INPUT);
}
void loop() {
smartStream[0] = analogRead (xAxis); /* Assigns array index 0 to joystick X axis */
smartStream[1] = analogRead (yAxis); /* Assigns array index 1 to joystick Y axis */
smartStream[2] = digitalRead (joySW); /* Assigns array index 2 to joystick switch */
smartStream[3] = digitalRead(buttonA); /* Assigns array index 3 to button A */
smartStream[4] = digitalRead(buttonB); /* Assigns array index 4 to button B */
smartStream[5] = digitalRead(buttonC); /* Assigns array index 5 to button C */
smartStream[6] = digitalRead(buttonD); /* Assigns array index 6 to button D */
smartStream[7] = digitalRead(buttonE); /* Assigns array index 7 to button E */
smartStream[8] = digitalRead(buttonF); /* Assigns array index 8 to button F */
radio.write(smartStream, sizeof(smartStream)); /* Pass the array to the Super SmartCar */
}
on the other end, the Mega2560 has most of the code because it is physically on the car. Here is an excerpt...
#include <SPI.h> /* Serial Peripheral Interface Library (required for NRF Radio) */
#include <RF24.h> /* NRF24 Radio Library (required) */
const int initCEPin = 8; /* Radio Chip Enable Digital Pin 8 */
const int initCSNPin = 53; /* Radio SPI Chip Select Digital Pin 53 */
const uint64_t pipe = 0xE8E8F0F0E1LL; /* Radio's addressing system */
RF24 radio(initCEPin, initCSNPin); /* Initialize the Radio */
int smartStream[9]; /* Create Communication Array for all functions */
int joySwitch;
bool btnAValue = true;
bool btnBValue = true;
bool btnCValue = true;
bool btnDValue = true;
bool btnEValue = true;
bool btnFValue = true;
void radioControl() {
radio.read( smartStream, sizeof(smartStream) ); /* Read in the smartStream Array */
smartStreamTest(); /* Tests the Radio Stream when pressing (and holding F) */
joyYValue = smartStream[0]; /* Assigns array index 0 to joystick Y axis */
joyXValue = smartStream[1]; /* Assigns array index 1 to joystick X axis */
joySwitch = smartStream[2]; /* Assigns array index 2 to joystick switch */
btnAValue = smartStream[3]; /* Assigns array index 3 to button A */
btnBValue = smartStream[4]; /* Assigns array index 4 to button B */
btnCValue = smartStream[5]; /* Assigns array index 5 to button C */
btnDValue = smartStream[6]; /* Assigns array index 6 to button D */
btnEValue = smartStream[7]; /* Assigns array index 7 to button E */
btnFValue = smartStream[8]; /* Assigns array index 8 to button F */
liteItUp(); /* LED Visual used to determine if the Radios are talking to each other */
}
Pressing the A button on the Uno, shows a zero or a one in the serial monitor on the Mega when I push the button. I want to latch the buttons for stay on and stay off capability. Whatever is the best way.. I'm for that! I just don't know how to go about it.
I would make another boolean value in that bool list, called someting like previousbtnEValue.
Then use an if() statement at the end of void radioControl.
Assuming btnEValue is momentarily HIGH during transmit...
if(btnEValue && previousbtnEValue) btnEValue = LOW; // if new value is high and old value was high, make value low
else btnEValue = HIGH; // else make value high
previoudbtnEValue = btnEValue;
I followed your instructions and when doing a Serial.println(btnEValue); I get 01010101010 repeating. If I press the button, I get all 1111111111's. If I lift off the button, it goes back to 01010101010.
the button IS high before pressing it. I put this at the bottom of radioControl() on the Mega (Slave).
if (btnEValue && previousbtnEValue){
btnEValue = LOW; // if new value is high and old value was high, make value low
}
else {
btnEValue = HIGH; // else make value high
}
previousbtnEValue = btnEValue;
I see now that the radio constantly transmits values, not just once when you press the button.
So the receiver value constantly toggles.
I think you have to do the same at the transmitter side.
Only send a "1" once after the button has been pressed.
The button also might need debouncing code.
If btnEValue is normally HIGH, and low when pressed, jsut flip one of the values.
Like this:
previousbtnEValue = !btnEValue;
Or send a '0' all the time, and a '1' once after a button press.
Leo..
I use that joy stick for thing and have also had problems keeping a true condition for change - the whole oldbutton != buttonnow kind of logic doesnt work so well.
here is what I ended up doing - spoiler - I added a button change state, and the logic not to change - or check for change - unless the state has changed. sure -!= with delay is easier - but I could not get it to work constantly..
so do this -
if oldbutton != new buttonread - then set a flag buttonState = 1.
then on next loop -
if ( buttonState ==0)
{
check that old button != newbutton read
if true - do ACTION you want AND set button state flag back
Knowing now that the transmitter constantly sends the button state, I would only change the transmitter side code. Not the code on the receiver.
Get a clean toggle of that state before you (constantly) transmit it.
Leo..
This is mind boggling for me. I tried the old button state code, but that doesnt work through the datastream.
What happens with the button state on the other end is sort of inconsequential right? It should transmit a 1 or a zero depending on how many times you press the button. So on the transmit end (master) I need to add code to this somehow.
#include <SPI.h> /* Serial Peripheral Interface Library (required) */
#include <RF24.h> /* NRF24 Radio Library */
const int initCEPin = 9; /* Chip Enable Digital Pin 9 */
const int initCSNPin = 10; /* SPI Chip Select Digital Pin 10 */
const int xAxis = A0; /* X Axis (Horizontal) */
const int yAxis = A1; /* Y Axis (Vertical) */
const int buttonA = 2; /* A button (top) */
const int buttonB = 3; /* B button (right) */
const int buttonC = 4; /* C button (bottom) */
const int buttonD = 5; /* D button (left) */
const int buttonE = 6; /* E button (bottom right) */
const int buttonF = 7; /* F button (bottom left) */
const int joySW = 8; /* ThumbStick Switch */
int statusE = false;
const uint64_t pipe = 0xE8E8F0F0E1LL; /* Radio's addressing system */
RF24 radio(initCEPin, initCSNPin); /* Initialize the Radio */
int smartStream[9]; /* Create Communication Array for all functions */
void setup() {
Serial.begin(115200);
radio.begin(); /* Open the Radio for communication */
radio.openWritingPipe(pipe); /* Open two-way Comm to the Slave Mega2560 */
pinMode(buttonA, INPUT);
pinMode(buttonB, INPUT); /* Only Digital pins are required to be defined here */
pinMode(buttonC, INPUT); /* The Analog Thumbstick is exempt */
pinMode(buttonD, INPUT);
pinMode(buttonE, INPUT);
pinMode(buttonF, INPUT);
pinMode (joySW, INPUT);
}
void loop() {
smartStream[0] = analogRead (xAxis); /* Assigns array index 0 to joystick X axis */
smartStream[1] = analogRead (yAxis); /* Assigns array index 1 to joystick Y axis */
smartStream[2] = digitalRead (joySW); /* Assigns array index 2 to joystick switch */
smartStream[3] = digitalRead(buttonA); /* Assigns array index 3 to button A */
smartStream[4] = digitalRead(buttonB); /* Assigns array index 4 to button B */
smartStream[5] = digitalRead(buttonC); /* Assigns array index 5 to button C */
smartStream[6] = digitalRead(buttonD); /* Assigns array index 6 to button D */
smartStream[7] = digitalRead(buttonE); /* Assigns array index 7 to button E */
smartStream[8] = digitalRead(buttonF); /* Assigns array index 8 to button F */
radio.write(smartStream, sizeof(smartStream)); /* Pass the array to the Super SmartCar */
}
You cant use while loops or delays because that stops the train.
I followed your instructions and when doing a Serial.println(btnEValue); I get 01010101010 repeating. If I press the button, I get all 1111111111's. If I lift off the button, it goes back to 01010101010.
the button IS high before pressing it. I put this at the bottom of radioControl() on the Mega (Slave).
if (btnEValue && previousbtnEValue){
btnEValue = LOW; // if new value is high and old value was high, make value low
}
else {
btnEValue = HIGH; // else make value high
}
previousbtnEValue = btnEValue;
I think you were close, but your logic is a little wrong. You can do this in the slave if you want. First, add a new byte variable btnEControl which you will toggle between 0 and 1 (that is off and on). Initialize with default on or off. You will need to add code in loop() to respond to btnEControl depending what you want btnE to turn on and off.
if(btnEvalue == LOW && previousbtnEvalue == HIGH)//only respond to a button press change of value
{
btnEContrtol != btnEControl;
}
previousbtnEValue = btnEValue;
If bounce is an issue, that can be addressed.
#include <SPI.h> /* Serial Peripheral Interface Library (required for NRF Radio) */
#include <RF24.h> /* NRF24 Radio Library (required) */
const int initCEPin = 8; /* Radio Chip Enable Digital Pin 8 */
const int initCSNPin = 53; /* Radio SPI Chip Select Digital Pin 53 */
const uint64_t pipe = 0xE8E8F0F0E1LL; /* Radio's addressing system */
RF24 radio(initCEPin, initCSNPin); /* Initialize the Radio */
int smartStream[9]; /* Create Communication Array for all functions */
int joySwitch;
bool btnAValue = true;
bool btnBValue = true;
bool btnCValue = true;
bool btnDValue = true;
bool btnEValue = true;
bool previousbtnEValue = true; //add previous value variable
bool btnFValue = true;
bool btnEControl = true; // add control variable default initial value
void radioControl() {
radio.read( smartStream, sizeof(smartStream) ); /* Read in the smartStream Array */
smartStreamTest(); /* Tests the Radio Stream when pressing (and holding F) */
joyYValue = smartStream[0]; /* Assigns array index 0 to joystick Y axis */
joyXValue = smartStream[1]; /* Assigns array index 1 to joystick X axis */
joySwitch = smartStream[2]; /* Assigns array index 2 to joystick switch */
btnAValue = smartStream[3]; /* Assigns array index 3 to button A */
btnBValue = smartStream[4]; /* Assigns array index 4 to button B */
btnCValue = smartStream[5]; /* Assigns array index 5 to button C */
btnDValue = smartStream[6]; /* Assigns array index 6 to button D */
btnEValue = smartStream[7]; /* Assigns array index 7 to button E */
btnFValue = smartStream[8]; /* Assigns array index 8 to button F */
if(btnEvalue == LOW && previousbtnEvalue == HIGH)//only respond to a button press change of value
{
btnEControl != btnEControl;
}
previousbtnEValue = btnEValue;
liteItUp(); /* LED Visual used to determine if the Radios are talking to each other */
}
Here is the way I did it after your instructions...
void radioControl() {
radio.read( smartStream, sizeof(smartStream) ); /* Read in the smartStream Array */
smartStreamTest(); /* Tests the Radio Stream when pressing (and holding F) */
joyYValue = smartStream[0]; /* Assigns array index 0 to joystick Y axis */
joyXValue = smartStream[1]; /* Assigns array index 1 to joystick X axis */
joySwitch = smartStream[2]; /* Assigns array index 2 to joystick switch */
btnAValue = smartStream[3]; /* Assigns array index 3 to button A */
btnBValue = smartStream[4]; /* Assigns array index 4 to button B */
btnCValue = smartStream[5]; /* Assigns array index 5 to button C */
btnDValue = smartStream[6]; /* Assigns array index 6 to button D */
btnEValue = smartStream[7]; /* Assigns array index 7 to button E */
btnFValue = smartStream[8]; /* Assigns array index 8 to button F */
liteItUp(); /* LED Visual used to determine if the Radios are talking to each other */
if(btnEValue == LOW && previousbtnEValue == HIGH) {//only respond to a button press change of value
btnEControl != btnEControl;
}
Serial.println(btnEControl);
previousbtnEValue = btnEValue;
I added these two variables:
bool previousbtnEValue = true;
bool btnEControl = true;
When I press down on the button and view the Serial.println statement in the serial monitor, I get:
01010101010.... when pressed and:
11111111111.... when not pressed.
I tried moving the println statement inside the if, but then it just behaves as a regular momentary.
I also tried moving it to the very bottom. Same result as above. Not sure how much debounce has to do with it.. not very experienced with that.
I don't think you are seeing the effect of bounce.
int smartStream[9];
I'm not sure if this is an issue.
For quick test purposes change it to byte smartStream[9] in both TX and RX codes, and divide the analogRead() values in the TX code by 4.
See if this has an effect on the "1010101" train.
What you should be seeing is "111111" before any button is pressed because default btnEControl
=true.
Your press and release (or press and hold) it should switch to all 0's. A second press should switch back to all ones. A third press to 0's again.
The alternating ones and zeros is certainly confusing. In the original code, before you tried to make the button press state persistant, were you seeing strings of pure 1's and pure 0's when the button was either held down or not being pressed.?
For now, I'm suspicious of the TX side.
What does smartStreamTest() tell you?
cattledog:
The alternating ones and zeros is certainly confusing. In the original code, before you tried to make the button press state persistant, were you seeing strings of pure 1's and pure 0's when the button was either held down or not being pressed.?
The alternating 1010101 code was because OP already added the toggle code in the receiver.
As said, the receiver should not be changed if the transmitter sends all the time.
Just toggle the value to be send by the transmitter.
Leo..
I tried changing to byte on both sides, but nothing works then. Probably because at least int is needed for the 1023 values of the joystick? Im guessing.
dividing the digitalRead values by 4 made it stop working too. I am okay with doing this on the transmit side. The code is much smaller. This is the whole transmit side:
#include <SPI.h> /* Serial Peripheral Interface Library (required) */
#include <RF24.h> /* NRF24 Radio Library */
const int initCEPin = 9; /* Chip Enable Digital Pin 9 */
const int initCSNPin = 10; /* SPI Chip Select Digital Pin 10 */
const int xAxis = A0; /* X Axis (Horizontal) */
const int yAxis = A1; /* Y Axis (Vertical) */
const int buttonA = 2; /* A button (top) */
const int buttonB = 3; /* B button (right) */
const int buttonC = 4; /* C button (bottom) */
const int buttonD = 5; /* D button (left) */
const int buttonE = 6; /* E button (bottom right) */
const int buttonF = 7; /* F button (bottom left) */
const int joySW = 8; /* ThumbStick Switch */
const uint64_t pipe = 0xE8E8F0F0E1LL; /* Radio's addressing system */
RF24 radio(initCEPin, initCSNPin); /* Initialize the Radio */
int smartStream[9]; /* Create Communication Array for all functions */
void setup() {
Serial.begin(115200);
radio.begin(); /* Open the Radio for communication */
radio.openWritingPipe(pipe); /* Open two-way Comm to the Slave Mega2560 */
pinMode(buttonA, INPUT);
pinMode(buttonB, INPUT); /* Only Digital pins are required to be defined here */
pinMode(buttonC, INPUT); /* The Analog Thumbstick is exempt */
pinMode(buttonD, INPUT);
pinMode(buttonE, INPUT);
pinMode(buttonF, INPUT);
pinMode (joySW, INPUT);
}
void loop() {
smartStream[0] = analogRead (xAxis); /* Assigns array index 0 to joystick X axis */
smartStream[1] = analogRead (yAxis); /* Assigns array index 1 to joystick Y axis */
smartStream[2] = digitalRead (joySW); /* Assigns array index 2 to joystick switch */
smartStream[3] = digitalRead(buttonA); /* Assigns array index 3 to button A */
smartStream[4] = digitalRead(buttonB); /* Assigns array index 4 to button B */
smartStream[5] = digitalRead(buttonC); /* Assigns array index 5 to button C */
smartStream[6] = digitalRead(buttonD); /* Assigns array index 6 to button D */
smartStream[7] = digitalRead(buttonE);; /* Assigns array index 7 to button E */
//Serial.println(smartStream[7]);
smartStream[8] = digitalRead(buttonF); /* Assigns array index 8 to button F */
radio.write(smartStream, sizeof(smartStream)); /* Pass the array to the Super SmartCar */
}
The thing that baffles me is, the array.. smartStream[7] = digitalRead(buttonE); .. that is constantly polling the transmit side and pulling real time data on keypress. (or the other way around, but you know what I mean?) so to change the array, smartStream[7] has to equal something else.. an intermediate variable that contains the state change? Here is the receive side stuff that matters....
int smartStream[9]; /* Create Communication Array for all functions */
int joySwitch; /* Variable for the Joystick Switch */
int joyXValue = 0; /* Begin with 0 power applied to Joystick X Axis */
int joyYValue = 0; /* Begin with 0 power applied to Joystick Y Axis */
bool btnAValue = true; /* unAssigned */
bool btnBValue = true; /* Assigned to Zero Turn to the Right */
bool btnCValue = true; /* unAssigned */
bool btnDValue = true; /* Assigned to Zero Turn to the Left */
bool btnEValue = true; /* unAssigned */
bool btnFValue = true; /* Used for Test Mode so we can see communications between Master/Slave */
bool testMode = true; /* Used for turning Test Mode on/off so we can use F for something else */
bool previousbtnEValue = true;
bool btnEControl = true;
void radioControl() {
radio.read( smartStream, sizeof(smartStream) ); /* Read in the smartStream Array */
smartStreamTest(); /* Tests the Radio Stream when pressing (and holding F) */
joyYValue = smartStream[0]; /* Assigns array index 0 to joystick Y axis */
joyXValue = smartStream[1]; /* Assigns array index 1 to joystick X axis */
joySwitch = smartStream[2]; /* Assigns array index 2 to joystick switch */
btnAValue = smartStream[3]; /* Assigns array index 3 to button A */
btnBValue = smartStream[4]; /* Assigns array index 4 to button B */
btnCValue = smartStream[5]; /* Assigns array index 5 to button C */
btnDValue = smartStream[6]; /* Assigns array index 6 to button D */
btnEValue = smartStream[7]; /* Assigns array index 7 to button E */
btnFValue = smartStream[8]; /* Assigns array index 8 to button F */
liteItUp(); /* LED Visual used to determine if the Radios are talking to each other */
if (btnEValue == LOW && previousbtnEValue == HIGH) { //only respond to a button press change of value
btnEControl != btnEControl;
}
Serial.println(btnEControl);
previousbtnEValue = btnEValue;
}
smartStreamTest allows me to push the F button and show all of the states of each switch all at once in a nicely formatted view.
Without any new code, pressing E shows 1 before press, 0 during press, back to 1 letting off. I think as it should without modification. (to answer your questions I caught after re-reading)
As said, the receiver should not be changed if the transmitter sends all the time.
Just toggle the value to be send by the transmitter.
I understand that this can be solved at the transmitter side.
But the way I would prefer to do it is on the slave where the rest of the programming (mostly) resides.
The OP expressed a desire to resolve it at the RX end, and I was trying to accomodate.
In the code he posted in #11 he is toggling the control value. If the transmitter sends a 1 or a 0 depending on the digitalRead() of the button on the TX side then the RX should only be toggling on the state change of the transmitted/received digitalRead() value when the button becomes pressed. Where are the transmitted low/high/low/high transitions coming from when button is held down.
What am I missing? Is the smartStream buffer cleared after reading, and he is reading faster than transmitting? Perhaps he should only be reading if there is new data.
Wish I knew. You guys are always so helpful and I hate bothering you with it, but it seems pretty difficult for some reason. I would be fine with moving the issue to the transmitter side if that would be the most efficient. It's all good anyway.. they both have to be in play when running it with remote control, so I guess it doesnt really matter. Merry Christmas everyone!
I am missing something. Not associating things properly. I do not care in this case about an output pins state (at least I don't see it). I am concerned with flipping the input pins state, so I cannot fathom how to go about changing this code, which is based on this: https://www.arduino.cc/en/tutorial/switch
btnEVal = digitalRead(buttonE);
if (btnEVal == HIGH && btnEPreVal == LOW && millis() - time > debounce) {
if (outputPinState == HIGH) {
outputPinState = LOW;
}
else {
outputPinState = HIGH;
}
time = millis();
}
digitalWrite(outputPin, outputPinState);
// Serial.print(btnERes);
Serial.print(btnEPreVal);
// btnEPreVal = LOW;
here is the entire transmit side of the code..
#include <SPI.h> /* Serial Peripheral Interface Library (required) */
#include <RF24.h> /* NRF24 Radio Library */
const int initCEPin = 9; /* Chip Enable Digital Pin 9 */
const int initCSNPin = 10; /* SPI Chip Select Digital Pin 10 */
const int xAxis = A0; /* X Axis (Horizontal) */
const int yAxis = A1; /* Y Axis (Vertical) */
const int buttonA = 2; /* A button (top) */
const int buttonB = 3; /* B button (right) */
const int buttonC = 4; /* C button (bottom) */
const int buttonD = 5; /* D button (left) */
const int buttonE = 6; /* E button (bottom right) */
const int buttonF = 7; /* F button (bottom left) */
const int joySW = 8; /* ThumbStick Switch */
int outputPin = 13;
int outputPinState = LOW;
int btnEVal; /* Current button values (LOW or HIGH) to start */
int btnEPreVal = LOW; /* Previous button values (LOW or HIGH) */
long time = 0; /* Starts the timer at Zero for debounce purposes */
long debounce = 200; /* Debounce in milliseconds */
const uint64_t pipe = 0xE8E8F0F0E1LL; /* Radio's addressing system */
RF24 radio(initCEPin, initCSNPin); /* Initialize the Radio */
int smartStream[9]; /* Create Communication Array for all functions */
void setup() {
Serial.begin(115200);
radio.begin(); /* Open the Radio for communication */
radio.openWritingPipe(pipe); /* Open two-way Comm to the Slave Mega2560 */
pinMode(buttonA, INPUT);
pinMode(buttonB, INPUT); /* Only Digital pins are required to be defined here */
pinMode(buttonC, INPUT); /* The Analog Thumbstick is exempt */
pinMode(buttonD, INPUT);
pinMode(buttonE, INPUT_PULLUP);
pinMode(buttonF, INPUT);
pinMode (joySW, INPUT);
}
void loop() {
btnEVal = digitalRead(buttonE);
if (btnEVal == HIGH && btnEPreVal == LOW && millis() - time > debounce) {
if (outputPinState == HIGH) {
outputPinState = LOW;
}
else {
outputPinState = HIGH;
}
time = millis();
}
digitalWrite(outputPin, outputPinState);
// Serial.print(btnERes);
Serial.print(btnEPreVal);
// btnEPreVal = LOW;
btnEPreVal = btnEVal;
smartStream[0] = analogRead (xAxis); /* Assigns array index 0 to joystick X axis */
smartStream[1] = analogRead (yAxis); /* Assigns array index 1 to joystick Y axis */
smartStream[2] = digitalRead (joySW); /* Assigns array index 2 to joystick switch */
smartStream[3] = digitalRead(buttonA); /* Assigns array index 3 to button A */
smartStream[4] = digitalRead(buttonB); /* Assigns array index 4 to button B */
smartStream[5] = digitalRead(buttonC); /* Assigns array index 5 to button C */
smartStream[6] = digitalRead(buttonD); /* Assigns array index 6 to button D */
smartStream[7] = digitalRead(buttonE); /* Assigns array index 7 to button E */
Serial.println(smartStream[7]);
smartStream[8] = digitalRead(buttonF); /* Assigns array index 8 to button F */
radio.write(smartStream, sizeof(smartStream)); /* Pass the array to the Super SmartCar */
}