Help with coding...
hi i'm stuck on keypad, because want 3 products 111 beats per minute. if press 1 once saves variable of 1, if press again saves in variable 1, etc... calculates. code supplied have far , kind of explains happening, have contributed.
code v0.0:
"
"
code v0.0:
"
code: [select]
#include "arduino.h"
#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 row pinouts of keypad
byte colpins[cols] = {8, 7, 6}; //connect column pinouts of 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 convert = 0;
int total = 0;
int run = 0;
int x = 0;
int input = 0;
int varin = 0;
int count = 0;
int vardp = 0;
int varcalc = 1;
void setup()
{
// put setup code here, run once:
serial.begin(9600);
pinmode(2,input);
pinmode(5,output);
pinmode(4,output);
}
void loop()
{
// put main code here, run repeatedly:
char key = keypad.getkey();
if (digitalread(2))
{
if( ( run ) == ( 0 ) )
{
varcalc = 0;
varone = 0;
vartwo = 0;
varthree = 0;
one1 = 0;
two2 = 0;
three3 = 0;
convert = 0;
total = 0;
run = 1;
}
else
{
if( ((varone) == (0)) && ((vartwo)==(0)) && ((varthree)==(0)) )
{
if(key)
{
switch (key)
{
case '0':
one1 = 0;
varcalc = 0;
varone = 1;
break;
case '1':
one1 = 1;
varcalc = 0;
varone = 1;
break;
case '2':
one1 = 2;
varcalc = 0;
varone = 1;
break;
case '3':
one1 = 3;
varcalc = 0;
varone = 1;
break;
case '4':
one1 = 4;
varcalc = 0;
varone = 1;
break;
case '5':
one1 = 5;
varcalc = 0;
varone = 1;
break;
case '6':
one1 = 6;
varcalc = 0;
varone = 1;
break;
case '7':
one1 = 7;
varcalc = 0;
varone = 1;
break;
case '8':
one1 = 8;
varcalc = 0;
varone = 1;
break;
case '9':
one1 = 9;
varcalc = 0;
varone = 1;
break;
}
}
}
else
{
if( ((varone) == (1)) && ((vartwo)==(0)) && ((varthree)==(0)) )
{
if(key)
{
switch (key)
{
case '0':
two2 = 0;
varcalc = 0;
vartwo = 1;
break;
case '1':
two2 = 1;
varcalc = 0;
vartwo = 1;
break;
case '2':
two2 = 2;
varcalc = 0;
vartwo = 1;
break;
case '3':
two2 = 3;
varcalc = 0;
vartwo = 1;
break;
case '4':
two2 = 4;
varcalc = 0;
vartwo = 1;
break;
case '5':
two2 = 5;
varcalc = 0;
vartwo = 1;
break;
case '6':
two2 = 6;
varcalc = 0;
vartwo = 1;
break;
case '7':
two2 = 7;
varcalc = 0;
vartwo = 1;
break;
delay(11);
case '8':
two2 = 8;
varcalc = 0;
vartwo = 1;
break;
case '9':
two2 = 9;
varcalc = 0;
vartwo = 1;
break;
}
}
}
else
{
if( ((varone) == (1)) && ((vartwo)==(1)) && ((varthree)==(0)) )
{
if(key)
{
switch (key)
{
case '0':
three3 = 0;
varcalc = 0;
varthree = 1;
break;
case '1':
three3 = 1;
varcalc = 0;
varthree = 1;
break;
case '2':
three3 = 2;
varcalc = 0;
varthree = 1;
break;
case '3':
three3 = 3;
varcalc = 0;
varthree = 1;
break;
delay(11);
case '4':
three3 = 4;
varcalc = 0;
varthree = 1;
break;
case '5':
three3 = 5;
varcalc = 0;
varthree = 1;
break;
case '6':
three3 = 6;
varcalc = 0;
varthree = 1;
break;
delay(11);
case '7':
three3 = 7;
varcalc = 0;
varthree = 1;
break;
case '8':
three3 = 8;
varcalc = 0;
varthree = 1;
break;
case '9':
three3 = 9;
varcalc = 0;
varthree = 1;
break;
delay(11);
}
}
}
}
}
}
}
else
{
if( ( varcalc ) == ( 0 ) )
{
if( ((varone) == (1)) && ((vartwo)==(0)) && ((varthree)==(0)) )
{
convert = ((60000)/(one1));
varcalc = 1;
}
else
{
if( ((varone) == (1)) && ((vartwo)==(1)) && ((varthree)==(0)) )
{
total = ( ( (one1) * (10) ) + ( (two2) ) ) ;
convert = ( ( 60000 )/ ( total ) );
varcalc = 1;
}
else
{
if( ((varone) == (1)) && ((vartwo)==(1)) && ((varthree)==(1)) )
{
total = ( ( ( (one1) * (1000) ) + ( (two2) * (100) ) ) + ( three3 ) );
convert = ( ( 60000 )/ ( total ) );
varcalc = 1;
}
else
{
varcalc = 1;
}
}
}
}
else
{
run = 0 ;
digitalwrite(4,high);
analogwrite(5,255);
delay( 11 );
analogwrite(5,0);
digitalwrite(4,low);
delay( convert );
}
}
}
"
it's hard tell what's going on , what's supposed happen, can tell delays between "break" , next "case" never executed, may not there.
something isn't there should be, pair of code tags.
(why) (you) have (so) many (unnecessary) parentheses?
something isn't there should be, pair of code tags.
code: [select]
if( ((varone) == (0)) && ((vartwo)==(0)) && ((varthree)==(0)) )
(why) (you) have (so) many (unnecessary) parentheses?
Arduino Forum > Topics > Robotics (Moderator: fabioc84) > Help with coding...
arduino
Comments
Post a Comment