This is a new code version of V0.1
Code V0.2:
#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'#','0','*'}
};
byte rowPins[ROWS] = {12, 11, 10, 9}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
int VARone = 0;
int VARtwo = 0 ;
int VARthree = 0;
int One1 = 0;
int Two2 = 0;
int Three3 = 0;
int total = 0;
void setup()
{
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(2,INPUT);
pinMode(5,OUTPUT);
pinMode(4,OUTPUT);
}
void loop()
{
// put your main code here, to run repeatedly:
if (digitalRead(2))//Reset Loop
{
VARone = (0);
VARtwo = (0);
VARthree = (0);
One1 = (0);
Two2 = (0);
Three3 = (0);
total = (0);
}
else
{
if(digitalRead(3))//Calculation loop
{
if(VARone == 1)//Runs calculation when there is only one variable
{
total = (One1);//Takes one inputted number like; '5'
}
else
{
if((VARone == 1)&&(VARtwo == 1))//Runs calculation when there is only two variables
{
total = (((One1)*(10))+((Two2)));//Takes two inputted numbers and calculates like; '60'
}
else
{
if((VARone == 1)&&(VARtwo == 1)&&(VARthree== 1))//Runs calculation when there is only three variables
{
total = ((((One1)*(100))+((Two2)*(10)))+(Three3));//Takes three inputted numbers and calculates like; '111'
}
}
}
}
else//keypad loop
{
char key = keypad.getKey();
Serial.println(One1);
delay(11);
if((VARone)==(0))//Test if variable one is equal to 0
{
//Get key from 0 - 9 and set it to variable one
char key = keypad.getKey();
if(key != NO_KEY)
{
One1==(key);
VARone==1;
}
}
else
{
delay(11);
if(((VARone)==(1))&&((VARtwo)==(0)))//Test variable one is equal to 1, whilst variable two is equal to 0
{
//Get key from 0 - 9 and set it to variable two
char key = keypad.getKey();
if(key != NO_KEY)
{
Two2==(key);
VARtwo==1;
}
}
else
{
delay(11);
if(((VARone)==(1))&&((VARtwo)==(1))&&((VARthree)==(0)))//Test variable one and variable two is equal to 1, whilst variable three is equal to 0
{
//Get key from 0 - 9 and set it to variable three
char key = keypad.getKey();
if(key != NO_KEY)
{
Three3==(key);
VARthree==1;
}
}
else//loop
{
digitalWrite(4,HIGH);
analogWrite(5,255);
delay(11);
analogWrite(5,0);
digitalWrite(4,LOW);
delay((60000)/(total));//makes a delay, e.g. 60000/111 = 540.540540541ms
}
}
}
}
}
}