hey guys i have a huge code .... but some small part of it give me problems
i have 6 push buttons
arduino imput have the GND
look at picture ...below
what i want .... to move a stepper motor to a position manually
in the while loop i whant to increment or decrement the led (PWM) with two buttons up and down
when i exit the while loop ... to set the value to 0
what i get.....
when i enter the main while loop .... the code enter in both IF, inside the while ..... causing me 0 1 0 1 0 1 0 and so on
const int buttonPinEnter = 8; // pin for the Enter button
const int buttonPinLeft = 9; // pin for the Up button
const int buttonPinUp = 11; // pin for the Enter button
const int buttonPinDown = 12; // pin for the Enter button
const int buttonPinRight = 13; // pin for the Down button
const int buttonPinEsc = 14; // pin for the Esc button
int i=0;
pinMode(buttonPinLeft, INPUT);
pinMode(buttonPinRight, INPUT);
pinMode(buttonPinEnter, INPUT);
pinMode(buttonPinEsc, INPUT);
pinMode(buttonPinUp, INPUT);
pinMode(buttonPinDown, INPUT);
pinMode(LedRosu, OUTPUT);
pinMode(LedGalben, OUTPUT);
pinMode(LedVerde, OUTPUT);
pinMode(Buzzer, OUTPUT);
the part of the code what give me problems ..
while (newMenuItem.getName()=="motorA"){
lcd.setCursor(0,0); //primul rand
lcd.print(" ALEGE-MOTOR A");
tone(Buzzer,Eb8,Q);
if(digitalRead(buttonPinUp) == HIGH);
{
i++;
payload.A = i * 10;
payload.B = 0;
payload.C = 0;
payload.D = 0;
payload.E = 0;
payload.F = 0;
payload.G = 0;
lcd.clear();
lcd.setCursor(0,1); //primul rand
lcd.print(i);
trimitere();
if (digitalRead(buttonPinEsc)== HIGH){break; i=0;}
digitalWrite(LedRosu, LOW);
digitalWrite(LedGalben, HIGH);
analogWrite(LedVerde, i);
}
if(digitalRead(buttonPinDown) == HIGH);
{
i--;
payload.A = i * 10;
payload.B = 0;
payload.C = 0;
payload.D = 0;
payload.E = 0;
payload.F = 0;
payload.G = 0;
lcd.clear();
lcd.setCursor(0,1); //primul rand
lcd.print(i);
trimitere();
if (digitalRead(buttonPinEsc)== HIGH){break; i=0;}
digitalWrite(LedRosu, LOW);
digitalWrite(LedGalben, HIGH);
analogWrite(LedVerde, i);
}
if (digitalRead(buttonPinEsc)== HIGH){break; i=0;}
}
i olso tried
while (newMenuItem.getName()=="motorC"){
lcd.clear();
lcd.setCursor(0,0); //primul rand
lcd.print(" ALEGE-MOTOR C");
//lcd.setCursor(0,1); //primul rand
//lcd.print(" <- DA -> "); // 1< 2> 3/\ 4\/
tone(Buzzer,Eb8,Q);
i=0;
while (digitalRead(buttonPinUp) == HIGH);
{
i++;
payload.A = 0;
payload.B = 0;
payload.C = i * 10;
payload.D = 0;
payload.E = 0;
payload.F = 0;
payload.G = 0;
lcd.clear();
lcd.setCursor(0,1); //primul rand
lcd.print(payload.C);
trimitere();
if (digitalRead(buttonPinEsc)== HIGH){break; i=0;}
digitalWrite(LedRosu, LOW);
digitalWrite(LedGalben, HIGH);
analogWrite(LedVerde, i);
}
while (digitalRead(buttonPinDown) == HIGH);
{
i++;
payload.A = 0;
payload.B = 0;
payload.C = i * -10;
payload.D = 0;
payload.E = 0;
payload.F = 0;
payload.G = 0;
lcd.clear();
lcd.setCursor(0,1); //primul rand
lcd.print(payload.C);
trimitere();
if (digitalRead(buttonPinEsc)== HIGH){break; i=0;}
digitalWrite(LedRosu, LOW);
digitalWrite(LedGalben, HIGH);
analogWrite(LedVerde, i);
}
if (digitalRead(buttonPinEsc)== HIGH){break; i=0;}
}
what i do wrong ??????
Untitled3.bmp (2.07 MB)