Skip to main content
added 155 characters in body
Source Link
Juraj
  • 18.3k
  • 4
  • 32
  • 50

I'm creating a program that works like a piano. I have four button, a piezo buzz and an LCD screen. I'm having a little trouble with the buttonstate.

Here is my program, when I run it the piezo buzz doesn't stop producing sound. The way it's suppose to work is when I push the green button, the piezo is suppose to produce a C sound but it doesn't. Can anyone please tell me what I've done wrong?

code:

#include <LiquidCrystal.h>

LiquidCrystal lcd(13, 12, 11, 10, 9, 8);

int buttonyellow = 3; int buttonred = 4; int buttongreen = 5; int buttonblue = 6;

int C,D,E,F;
int buzz = 7;

int buttonstate;

void setup() { lcd.begin(16, 2);

lcd.print("hello, world!");

Serial.begin(9600); pinMode(buttonyellow,INPUT); pinMode(buttonred,INPUT); pinMode(buttongreen,INPUT); pinMode(buttonblue,INPUT);

}

void loop() {

lcd.setCursor(0, 1);

lcd.print(millis() / 1000);

C = digitalRead(buttonyellow); D = digitalRead(buttonred); E = digitalRead(buttongreen); F = digitalRead(buttonblue);

buttonstate = digitalRead(C); if(buttonstate == HIGH){ tone(buzz,523); } else if ( buttonstate == LOW) { tone(buzz,1000);

}else{ noTone(buzz); }
delay(50); }

#include <LiquidCrystal.h>

LiquidCrystal lcd(13, 12, 11, 10, 9, 8);

int buttonyellow = 3; 
int buttonred = 4;
int buttongreen = 5;
int buttonblue = 6;

int C,D,E,F;  
int buzz = 7;

int buttonstate;

void setup()
{
  lcd.begin(16, 2);
  
  lcd.print("hello, world!");

  Serial.begin(9600);
  pinMode(buttonyellow,INPUT);
  pinMode(buttonred,INPUT);
  pinMode(buttongreen,INPUT);
  pinMode(buttonblue,INPUT);
}

void loop()
{
  lcd.setCursor(0, 1);

  lcd.print(millis() / 1000);
  
  C = digitalRead(buttonyellow);
  D = digitalRead(buttonred);
  E = digitalRead(buttongreen);
  F = digitalRead(buttonblue);
 
  buttonstate = digitalRead(C); 
  if(buttonstate == HIGH){ 
    tone(buzz,523); 
  }  else if ( buttonstate == LOW) {
    tone(buzz,1000); 
  }else{
   noTone(buzz); 
  }  
  delay(50); 
}

I'm creating a program that works like a piano. I have four button, a piezo buzz and an LCD screen. I'm having a little trouble with the buttonstate.

Here is my program, when I run it the piezo buzz doesn't stop producing sound. The way it's suppose to work is when I push the green button, the piezo is suppose to produce a C sound but it doesn't. Can anyone please tell me what I've done wrong?

code:

#include <LiquidCrystal.h>

LiquidCrystal lcd(13, 12, 11, 10, 9, 8);

int buttonyellow = 3; int buttonred = 4; int buttongreen = 5; int buttonblue = 6;

int C,D,E,F;
int buzz = 7;

int buttonstate;

void setup() { lcd.begin(16, 2);

lcd.print("hello, world!");

Serial.begin(9600); pinMode(buttonyellow,INPUT); pinMode(buttonred,INPUT); pinMode(buttongreen,INPUT); pinMode(buttonblue,INPUT);

}

void loop() {

lcd.setCursor(0, 1);

lcd.print(millis() / 1000);

C = digitalRead(buttonyellow); D = digitalRead(buttonred); E = digitalRead(buttongreen); F = digitalRead(buttonblue);

buttonstate = digitalRead(C); if(buttonstate == HIGH){ tone(buzz,523); } else if ( buttonstate == LOW) { tone(buzz,1000);

}else{ noTone(buzz); }
delay(50); }

I'm creating a program that works like a piano. I have four button, a piezo buzz and an LCD screen. I'm having a little trouble with the buttonstate.

Here is my program, when I run it the piezo buzz doesn't stop producing sound. The way it's suppose to work is when I push the green button, the piezo is suppose to produce a C sound but it doesn't. Can anyone please tell me what I've done wrong?

code:

#include <LiquidCrystal.h>

LiquidCrystal lcd(13, 12, 11, 10, 9, 8);

int buttonyellow = 3; 
int buttonred = 4;
int buttongreen = 5;
int buttonblue = 6;

int C,D,E,F;  
int buzz = 7;

int buttonstate;

void setup()
{
  lcd.begin(16, 2);
  
  lcd.print("hello, world!");

  Serial.begin(9600);
  pinMode(buttonyellow,INPUT);
  pinMode(buttonred,INPUT);
  pinMode(buttongreen,INPUT);
  pinMode(buttonblue,INPUT);
}

void loop()
{
  lcd.setCursor(0, 1);

  lcd.print(millis() / 1000);
  
  C = digitalRead(buttonyellow);
  D = digitalRead(buttonred);
  E = digitalRead(buttongreen);
  F = digitalRead(buttonblue);
 
  buttonstate = digitalRead(C); 
  if(buttonstate == HIGH){ 
    tone(buzz,523); 
  }  else if ( buttonstate == LOW) {
    tone(buzz,1000); 
  }else{
   noTone(buzz); 
  }  
  delay(50); 
}
Source Link
Chase
  • 11
  • 1

Need help with buttonstate

I'm creating a program that works like a piano. I have four button, a piezo buzz and an LCD screen. I'm having a little trouble with the buttonstate.

Here is my program, when I run it the piezo buzz doesn't stop producing sound. The way it's suppose to work is when I push the green button, the piezo is suppose to produce a C sound but it doesn't. Can anyone please tell me what I've done wrong?

code:

#include <LiquidCrystal.h>

LiquidCrystal lcd(13, 12, 11, 10, 9, 8);

int buttonyellow = 3; int buttonred = 4; int buttongreen = 5; int buttonblue = 6;

int C,D,E,F;
int buzz = 7;

int buttonstate;

void setup() { lcd.begin(16, 2);

lcd.print("hello, world!");

Serial.begin(9600); pinMode(buttonyellow,INPUT); pinMode(buttonred,INPUT); pinMode(buttongreen,INPUT); pinMode(buttonblue,INPUT);

}

void loop() {

lcd.setCursor(0, 1);

lcd.print(millis() / 1000);

C = digitalRead(buttonyellow); D = digitalRead(buttonred); E = digitalRead(buttongreen); F = digitalRead(buttonblue);

buttonstate = digitalRead(C); if(buttonstate == HIGH){ tone(buzz,523); } else if ( buttonstate == LOW) { tone(buzz,1000);

}else{ noTone(buzz); }
delay(50); }