So, i'm busy into my Uni project where I aim to have a arduino circuit that sets different lights on for different levels of sounds/vibrations detected by the Piezo disc.(im using Arduino UNO)
Right now i'm trying to get the button to trigger the LED's to turn on, upon press, or at least for 1ms.
But I don't even get that, I've even uploaded other code with the button trigger, re arranged the pins in code correctly and it works just fine.
I've also changed the "boolean LEDgreenon;" to true manually in code and it turns on the LED as commanded.
I know its probably some small mistake, but I've been at this for ages and could use some help.
Here is my code:
int ledpins[] = { 4, 9, 10, 11 };
int pinCount = 4;
int speakeread = A0;
int pinbutton = 3;
int buttonread;
int LEDgreen;
int LEDyellow;
int LEDred;
boolean LEDgreenon;
boolean LEDyellowon;
boolean LEDredon;
int bob = LOW;
void setup()
{
for (int outLEDpin = 0; outLEDpin < pinCount; outLEDpin++) {
pinMode(ledpins[outLEDpin], OUTPUT);
}
pinMode(speakeread, INPUT);
pinMode(pinbutton, INPUT);
Serial.begin(9600);
}
void loop()
{
buttonread = digitalRead(pinbutton);
if(buttonread == HIGH){
LEDgreenon = true;
LEDyellowon = true;
LEDredon = true;
}
if(LEDgreenon == true){
//denys for function
}else{
ledpins[3] = LEDgreen;
}
if(LEDyellowon == true){
}else{
ledpins[2] = LEDyellow;
}
if(LEDredon == true){
}else{
ledpins[1] = LEDred;
}
for (int outLEDpin = 0; outLEDpin < pinCount; outLEDpin++) {
digitalWrite(ledpins[outLEDpin], HIGH);
}
Serial.println(buttonread);
}
This is the particular part that isn't working
buttonread = digitalRead(pinbutton);
if(buttonread == HIGH){
LEDgreenon = true;
LEDyellowon = true;
LEDredon = true;
}
Button read is reading 1 when i press it down, so im guessing the button is reading high & also when I put Serial.println(buttonread); into the if statement it also prints when pressed, but LED's dont turn on?