#include "stdafx.h"
#include <iostream>
using namespace std;
int button1 ()
{ char ans;
int button;
int led1[5] ={1,1,1,1,1};
do {
cout << led1[0]<<led1[1]<<led1[2]<<led1[3]<<led1[4];
cout <<endl;
cout <<"01234"<<endl;
cout <<"Enter Button: ";
cin >>button;
if (button <= 4)
{
led1[button] = 0;
}
else if (button == 5)
{ cout << "Done (Y or N): " << endl;
cin>> ans;
cout << endl;}
else if (button >= 6)
{cout <<endl;
cout << "Invalid input" <<endl;
cout <<endl;}
}
while ((ans !='Y')&&(ans !='y'));
return true;
}
int button2 ()
{ char ans;
int button;
int frstrn = 0;
int led2[5] = {1,1,1,1,1};
frstrn = frstrn + 1;
do {
cout << led2[0]<<led2[1]<<led2[2]<<led2[3]<<led2[4];
cout <<endl;
cout <<"012345"<<endl;
cout <<"Enter Button: ";
cin >>button;
if (button <= 4)
{
led2[button] = 0;
}
else if (button == 5)
{ cout << "Done (Y or N): " << endl;
cin>> ans;
cout << endl;}
else if (button >= 6)
{cout <<endl;
cout << "Invalid input" <<endl;
cout <<endl;}
}
while ((ans !='Y')&&(ans !='y'));
return true;
}
int button3 ()
{
char ans;
int button;
int frstrn = 0;
int led3[5] = {1,1,1,1,1};
frstrn = frstrn + 1;
do {
cout << led3[0]<<led3[1]<<led3[2]<<led3[3]<<led3[4];
cout <<endl;
cout <<"012345"<<endl;
cout <<"Enter Button: ";
cin >>button;
if (button <= 4)
{
led3[button] = 0;
}
else if (button == 5)
{ cout << "Done (Y or N): " << endl;
cin>> ans;
cout << endl;}
else if (button >= 6)
{cout <<endl;
cout << "Invalid input" <<endl;
cout <<endl;}
}
while ((ans !='Y')&&(ans !='y'));
return true;
}
int button4 ()
{
char ans;
int button;
int frstrn = 0;
int led4[5] = {1,1,1,1,1};
frstrn = frstrn + 1;
do {
cout << led4[0]<<led4[1]<<led4[2]<<led4[3]<<led4[4];
cout <<endl;
cout <<"012345"<<endl;
cout <<"Enter Button: ";
cin >>button;
if (button <= 4)
{
led4[button] = 0;
}
else if (button == 5)
{ cout << "Done (Y or N): " << endl;
cin>> ans;
cout << endl;}
else if (button >= 6)
{cout <<endl;
cout << "Invalid input" <<endl;
cout <<endl;}
}
while ((ans !='Y')&&(ans !='y'));
return true;
}
int main()
{
int button;
do {
cout << " " << endl;
cout << "Main menu" << endl;
cout << " " << endl;
cout << "1.....Button 1" << endl;
cout << "2.....Button 2" << endl;
cout << "3.....Button 3" << endl;
cout << "4.....Button 4" << endl;
cout << "5.....Ends Program" << endl;
cout << "Please make your choice: ";
cin >> button;
cout << " " << endl;
if (button == 1)
{
int led1[5] = {1,1,1,1,1};
button1();}
else if (button == 2)
button2();
else if (button == 3)
button3();
else if (button == 4)
button4();
}
while (button != 5);
return 0;
}
what it does:
goes to a function and changes the value of an array from 1 (on) to 0 (off) and resets to on when i leave the function and then return to it.
what it needs to do:
not reset the function. i want to be able to push button 1 and turn off two or three or whatever leds and then go to main menu and push button 2 and do the same then return to button and and turn the rest of the lights off. they only need to be on once but i need to be able to pick and choose what lights are shut off.
also i know this isnt the correct syntax for the arduino but once i get it on the command line i can make it work for the arduino.
thanks-
dustin