Hello Everyone, I have some programming background but not much with microcontrollers and wanted to try this out. The idea is using 10 push buttons as inputs. 5 Yes and 5 no answers. People will have the chance to enter yes or no using 1 of the 10 switches for 5 different questions. I want to take these answers and feed them live using an Excel document using PLX-DAQ. I'm just having issues with code and implementing the Excel add in. Please any help would be useful!
My code is below.
int x = 0;
int row = 0;
int yesDoorOnePin = 2; //sets Door one yes to pin 2 on arduino.
int noDoorOnePin = 3; //sets Door one no to pin 3 on arduino.
int yesDoorTwoPin = 4; //sets Door two yes to pin 4 on arduino.
int noDoorTwoPin = 5; //sets Door two no to pin 5 on arduino.
int yesDoorThreePin = 6; //sets Door three yes to pin 6 on arduino.
int noDoorThreePin = 7;//sets Door three no to pin 7 on arduino.
int yesDoorFourPin = 8; //sets Door four yes to pin 8 on arduino.
int noDoorFourPin = 9; //sets Door four no to pin 9 on arduino.
int yesDoorFivePin = 10; //sets Door five yes to pin 10 on arduino.
int noDoorFivePin = 11; //sets Door five no to pin 11 on arduino.
byte yesDoorOneState = 0; //Sets state to zero, has not been pushed.
byte noDoorOneState = 0;
byte yesDoorTwoState = 0;
byte noDoorTwoState = 0;
byte yesDoorThreeState = 0;
byte noDoorThreeState = 0;
byte yesDoorFourState = 0;
byte noDoorFourState = 0;
byte yesDoorFiveState = 0;
byte noDoorFiveState = 0;
byte yesFirstButtonCounter = 1; //Counts how many times button is pressed.
byte noFirstButtonCounter = 0;
byte yesTwoButtonCounter = 0;
byte noTwoButtonCounter = 0;
byte yesThreeButtonCounter = 0;
byte noThreeButtonCounter = 0;
byte yesFourButtonCounter = 0;
byte noFourButtonCounter = 0;
byte yesFiveButtonCounter = 0;
byte noFiveButtonCounter = 0;
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
Serial.println("CLEARDATA");
Serial.println("LABEL, TIME, FirstDoorYes, First Door No, Second Door Yes, Second Door No, Third Door Yes, Third Door No, Fourth Door Yes, Fourth Door No, Fifth Door Yes, Fifth Door No");
pinMode(yesDoorOnePin, INPUT); // intializes the first yes doorbell as input
pinMode(noDoorOnePin, INPUT); // intializes the first no doorbell as input
pinMode(yesDoorTwoPin, INPUT); // initializes the second yes doorbell as input
/* pinMode(noDoorTwoPin, INPUT); // intializes the second no doorbell as input
pinMode(yesDoorThreePin, INPUT); // intializes the third yes doorbell as input
pinMode(noDoorThreePin, INPUT); // intializes the first yes doorbell as input
pinMode(yesDoorFourPin, INPUT); // intializes the first no doorbell as input
pinMode(noDoorFourPin, INPUT); // initializes the second yes doorbell as input
pinMode(noDoorFivePin, INPUT); // intializes the second no doorbell as input
pinMode(yesDoorFivePin, INPUT); // intializes the third yes doorbell as input
*/
}
void loop() {
//Serial.println("DATA, TIME");
yesDoorOneState = digitalRead(yesDoorOnePin); // Reads the state of yes switch for door one.
noDoorOneState = digitalRead (noDoorOnePin); // Reads the state of no switch for door one.
yesDoorTwoState = digitalRead(yesDoorTwoPin); // Reads the state of yes switch for door two.
/*
noDoorTwoState = digitalRead (noDoorTwoPin); // Reads the state of no switch for door two.
yesDoorThreeState = digitalRead(yesDoorThreePin); // Reads the state of yes switch for door three.
noDoorThreeState = digitalRead (noDoorThreePin); // Reads the state of no switch for door three.
yesDoorFourState = digitalRead(yesDoorFourPin); // Reads the state of yes switch for door four.
noDoorFourState = digitalRead (noDoorFourPin); // Reads the state of no switch for door four.
yesDoorFiveState = digitalRead(yesDoorFivePin); // Reads the state of yes switch for door five.
noDoorFiveState = digitalRead (noDoorFivePin); // Reads the state of no switch for door five.
*/
if (yesDoorOneState == HIGH) // If door one is pressed yes then...
{
Serial.println(yesFirstButtonCounter);
Serial.println("FirstButtonYes");
Serial.println(",");
yesFirstButtonCounter ++; //Adds 1
delay(1000);
}
if (noDoorOneState == HIGH) // If door no is pressed yes then...
{
Serial.println(noFirstButtonCounter); //Prints Value to excel sheet
Serial.println("FirstButtonNo");
Serial.println(",");
noFirstButtonCounter ++; //Adds 1
delay(1000);
}
if (yesDoorTwoState == HIGH) // If door one is pressed yes then...
{
Serial.print(yesTwoButtonCounter); //Prints Value to Excel Sheet
Serial.print("TwoButtonYes");
Serial.print (",");
yesTwoButtonCounter ++; //Adds 1
delay(1000);
}
/*
if (noDoorTwoState == HIGH) // If door no is pressed yes then...
{
noTwoButtonCounter ++; //Adds 1
Serial.print(noTwoButtonCounter); //Prints Value to excel sheet
Serial.print("NOtwo"); //Temp
delay(1000);
}
if (yesDoorThreeState == HIGH) // If door one is pressed yes then...
{
yesThreeButtonCounter ++; //Adds 1
Serial.print ("Balls");
Serial.print(yesThreeButtonCounter); //Prints Value to Excel Sheet
Serial.print("YESthree"); // temp
delay(1000);
}*/
/*
if (noDoorThreeState == HIGH) // If door no is pressed yes then...
{
noThreeButtonCounter ++; //Adds 1
Serial.print(noThreeButtonCounter); //Prints Value to excel sheet
Serial.print("NOthree"); //Temp
delay(1000);
}
if (yesDoorFourState == HIGH) // If door one is pressed yes then...
{
yesFourButtonCounter ++; //Adds 1
Serial.print(yesFourButtonCounter); //Prints Value to Excel Sheet
Serial.print("YESfour"); // temp
delay(1000);
}
if (noDoorFourState == HIGH) // If door no is pressed yes then...
{
noFourButtonCounter ++; //Adds 1
Serial.print(noFourButtonCounter); //Prints Value to excel sheet
delay(1000);
}
if (yesDoorFiveState == HIGH) // If door one is pressed yes then...
{
yesFiveButtonCounter ++; //Adds 1
Serial.print(yesFiveButtonCounter); //Prints Value to Excel Sheet
delay(1000);
}
if (noDoorFiveState == HIGH) // If door no is pressed yes then...
{
noFiveButtonCounter ++; //Adds 1
Serial.print(noFiveButtonCounter); //Prints Value to excel sheet
delay(1000);
//}*/
}
PERC.ino (5.81 KB)
