Pages: [1]   Go Down
Author Topic: Can I use a digital read and Analog read simo...  (Read 411 times)
0 Members and 1 Guest are viewing this topic.
Milwaukee, Wi USA
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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;}
}
Logged

Portugal
Offline Offline
God Member
*****
Karma: 6
Posts: 962
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: