Go Down

Topic: Can I use a digital read and Analog read simo... (Read 426 times) previous topic - next topic

ReggieRegReg

taneously? I have written code that verified, but when it loads into the board, I just get feedback. I am REALLY new to code / electronics etc.  When I upload the code w/o the digital read button, it works properly.
I am trying to make a simple cmos sequencer play in 2 different patterns triggered by the mounted button. I have an analog read assigned to the rate of the notes/delay.  
Again, any help is greatly appreciated, I have just started doing code/circuit building in the past 5 weeks.  

code:

byte ledPin[]={4,5,6,7,8};
int ledDelay;
int direction=1;
int currentLED=0;
unsigned long changeTime;
int potPin=2;
int button=12;

void setup() {
 for(int x=0; x<5; x++) {
   pinMode (ledPin
  • , OUTPUT);}
       changeTime= millis();
       pinMode (button, INPUT);
       digitalRead (button);
    }
    void loop () {
     ledDelay = analogRead (potPin);
     if((millis()-changeTime) >
     ledDelay) {
       changeLED();
       changeTime = millis();
       
     }
     if (button=0){changeLED();
     }
    if (button=1) {longvoice();
    }
    if (button=2){ button=0;
    }
    }

    void changeLED() {
     for (int x=0; x<5; x++) {
       digitalWrite(ledPin
  • , LOW);
     }
     digitalWrite (ledPin[currentLED],
     HIGH);
     currentLED += direction;
     if (currentLED == 4) {direction= -1;}
     if (currentLED ==0) {direction= 1;}
    }
    void longvoice() {
     for (int x=0; x<5; x++){
        digitalWrite(ledPin
  • , LOW);
     }
     digitalWrite (ledPin[currentLED],
     HIGH);
     currentLED += direction;
     if (currentLED == 4) {direction= -1;}
     if (currentLED ==0) {direction= 1;}
    }

Senso

This should be:
Code: [Select]
if (button[glow]==[/glow]0){changeLED();
}
if (button[glow]==[/glow]1) {longvoice();
}
if (button[glow]==[/glow]2){ button=0;

Go Up