Conditional Statement Help Request
i have arduino esplora rev04 board. trying make controller 1 of games , use linear potentiometer item selector. have written series of loops intent of checking state , if has changed print new result if has changed
however when run end constant stream of numbers based on slider is. if can point out went wrong or show me better way of doing obliged.
code: [select]
int lp = esplora.readslider();
int lp1;
int lp2;
if (lp > 918) lp1 = 1;
if (lp < 917 && lp > 816 ) lp1 = 2;
if (lp < 815 && lp > 714) lp1 = 3;
if (lp < 713 && lp > 612) lp1 = 4;
if (lp < 611 && lp > 510) lp1 = 5;
if (lp < 509 && lp > 408) lp1 = 6;
if (lp < 407 && lp > 306) lp1 = 7;
if (lp < 305 && lp > 204) lp1 = 8;
if (lp < 203 && lp > 102) lp1 = 9;
if (lp < 101) lp1 = 10;
if (lp1 != lp2 , lp1 == 1) { keyboard.write('1'); lp2 = lp1; };
if (lp1 != lp2 , lp1 == 2) { keyboard.write('2'); lp2 = lp1; };
if (lp1 != lp2 , lp1 == 3) { keyboard.write('3'); lp2 = lp1; };
if (lp1 != lp2 , lp1 == 4) { keyboard.write('4'); lp2 = lp1; };
if (lp1 != lp2 , lp1 == 5) { keyboard.write('5'); lp2 = lp1; };
if (lp1 != lp2 , lp1 == 6) { keyboard.write('6'); lp2 = lp1; };
if (lp1 != lp2 , lp1 == 7) { keyboard.write('7'); lp2 = lp1; };
if (lp1 != lp2 , lp1 == 8) { keyboard.write('8'); lp2 = lp1; };
if (lp1 != lp2 , lp1 == 9) { keyboard.write('9'); lp2 = lp1; };
if (lp1 != lp2 , lp1 == 10) { keyboard.write('0'); lp2 = lp1; };however when run end constant stream of numbers based on slider is. if can point out went wrong or show me better way of doing obliged.
code: [select]
if (lp1 != lp2 , lp1 == 1) { keyboard.write('1'); lp2 = lp1; };the comma operator not 1 want use. 1 want not @ clear.
Arduino Forum > Using Arduino > Programming Questions > Conditional Statement Help Request
arduino
Comments
Post a Comment