Repetitive 0's?
so posted topic few days ago , couple people helped me on how input multiple digit variables keypad. followed advice , can see 0's now. come in groups of 3 , spam lcd screen. would've posted in other topic didn't want confusion title. being said, hope else has experienced , solved or sees error in code.
i have code below , attach photo of problem.
there few comments here , there have given trying put them in when began redo of code. always, new. saying stuff beyond basics hard pressed me understand.
i have code below , attach photo of problem.
code: [select]
/* code allows top input values via 3x4 keypad display
on lcd screen in number format , alter rgb led color. can switch
which color edit * button. use # update colours
pins:
arduino lcd interface
5v vcc
gnd gnd
a5 scl
a4 sda
arduino keypad
8 1
7 2
6 3
5 4
4 5
3 6
2 7
arduino rgb
~220ohm resistors between digital pins , color pins
9 red
10 blue
11 green
gnd gnd
*/
#include <wire.h>
#include <liquidcrystal_i2c.h>
liquidcrystal_i2c lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, positive);
#include <keypad.h>
int yr = 0;
int yg = 0;
int yb = 0;
int digitra = 0;
int digitrb = 0;
int digitrc = 0;
int reddigit = 1;
int digitga= 0;
int digitgb= 0;
int digitgc= 0;
int greendigit = 1;
int digitba = 0;
int digitbb = 0;
int digitbc = 0;
int bluedigit = 1;
void keyred(int x){
if (reddigit==1){
digitra = x;
lcd.print(x);
}
if (reddigit==2){
digitrb = x;
lcd.print(x);
}
if (reddigit==3){
digitrc = x;
lcd.print(x);
}
reddigit = reddigit + 1;
if (reddigit >=4){}
}
void keygreen(int x){
if (reddigit==1){
digitga = x;
lcd.print(x);
}
if (reddigit==2){
digitgb = x;
lcd.print(x);
}
if (reddigit==3){
digitgc = x;
lcd.print(x);
}
greendigit = greendigit + 1;
if (greendigit >=4){}
}
void keyblue(int x){
if (bluedigit==1){
digitba = x;
lcd.print(x);
}
if (reddigit==2){
digitbb = x;
lcd.print(x);
}
if (reddigit==3){
digitbc = x;
lcd.print(x);
}
bluedigit = bluedigit + 1;
if (bluedigit >=4){}
}
int transform(int a, int b, int c){
int x;
x = a*100 + b*10 + c;
return x;
}
int color = 1; //allows control on color writing
int redpin = 9;
int greenpin = 10; //sets individual color pins
int bluepin =11;
const byte rows = 4; //four rows
const byte cols = 3; //three columns
char keys[rows][cols] = {
{'1','2','3'},
{'4','5','6'}, //creates keypad
{'7','8','9'},
{'*','0','#'}
};
byte rowpins[rows] = {5, 4, 3, 2}; //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 );
void setup(){
lcd.begin(16,2);
lcd.clear();
//test
serial.begin(9600);
//test
}
void loop(){
char key = keypad.getkey();
if(key == '#'){
lcd.clear();
analogwrite(redpin, transform(digitra, digitrb, digitbc));
analogwrite(greenpin, transform(digitga, digitgb, digitgc));
analogwrite(bluepin, transform(digitba, digitbb, digitbc));
lcd.setcursor(0,1);
lcd.write("r");
lcd.print(transform(digitra, digitrb, digitbc));
lcd.write("g");
lcd.print(transform(digitga, digitgb, digitgc));
lcd.write("b");
lcd.print(transform(digitba, digitbb, digitbc));
}
if(key == '*'){
color+=1;
}
if(color >= 4){
color = 1;
}
if(key >=0){
if(color == 1){
keyred(key);
}
if(color == 2){
keygreen(key);
}
if(color == 3){
keyblue(key);
}
}
}
there few comments here , there have given trying put them in when began redo of code. always, new. saying stuff beyond basics hard pressed me understand.
i start making change loop() follows:
as code stands now, execute of code when there no key press. means burning though code hundreds, if not thousands, of times each second, throwing zeroes on screen. run code above , pay attention values see. shouldn't see until press key. give starting place what's happening.
code: [select]
void loop(){
char key = keypad.getkey();
if (key != no_key){ // add new line
serial.print("key = "); // add new line
serial.println(key); // add new line
// put of existing code here
} // add new line
}
as code stands now, execute of code when there no key press. means burning though code hundreds, if not thousands, of times each second, throwing zeroes on screen. run code above , pay attention values see. shouldn't see until press key. give starting place what's happening.
Arduino Forum > Using Arduino > Programming Questions > Repetitive 0's?
arduino
Comments
Post a Comment